Created
February 15, 2019 23:15
-
-
Save jianminchen/049639760361d72ed140af40fbd15260 to your computer and use it in GitHub Desktop.
2015 Microsoft code screen - count binary tree node with one child
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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