Created
April 13, 2014 05:45
-
-
Save gabhi/10570853 to your computer and use it in GitHub Desktop.
Deepest left leaf node in a binary tree
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 class DeepestLeftLeafNodeFinder { | |
Node deepestNode; | |
int deepestNodeDepth; | |
public Node findDeepestLeftLeafNode(Node root,boolean isLeftNode,int depth){ | |
if(isLeftNode){ | |
if(depth > deepestNodeDepth){ | |
deepestNode = root; | |
deepestNodeDepth = depth; | |
} | |
} | |
if(root.getLeft() != null){ | |
findDeepestLeftLeafNode(root.getLeft(),true,depth + 1); | |
} | |
if(root.getRight() != null){ | |
findDeepestLeftLeafNode(root.getRight(),false,depth+1); | |
} | |
return deepestNode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment