Created
April 21, 2018 07:05
-
-
Save Kishy-nivas/0bffbddcb3a4735aa741e36cbf1b24b0 to your computer and use it in GitHub Desktop.
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
class GfG | |
{ | |
Node lca(Node node, int n1, int n2) | |
{ | |
Node root = node; | |
while(root != null){ | |
if(root.data>n1 && root.data >n2) | |
{ | |
root = root.left; | |
} | |
else if(root.data < n1 && root.data <n2){ | |
root = root.right; | |
} | |
else{ | |
return root; | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment