Created
May 25, 2019 13:05
-
-
Save madhur/0281011fdd676707e952b23c73f8f7cd to your computer and use it in GitHub Desktop.
Path length from root
This file contains hidden or 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 int pathLengthFromRoot(TreeNode root, int n1) { | |
| if (root == null) return 0; | |
| else { | |
| int out = 0; | |
| if ((root.data == n1) || (out = pathLengthFromRoot(root.left, n1)) > 0 | |
| || (out = pathLengthFromRoot(root.right, n1)) > 0) { | |
| return out + 1; | |
| } | |
| return 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment