Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created February 15, 2019 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/049639760361d72ed140af40fbd15260 to your computer and use it in GitHub Desktop.
Save jianminchen/049639760361d72ed140af40fbd15260 to your computer and use it in GitHub Desktop.
2015 Microsoft code screen - count binary tree node with one child
public static int countOneChildNode(Node node)
{
if(node==null) return 0;
return (((node.left!=null)!=(node.right!=null)? 1:0) + countOneChildNode(node.left) + countOneChildNode(node.right));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment