Skip to content

Instantly share code, notes, and snippets.

@Kishy-nivas
Created April 21, 2018 07:05
Show Gist options
  • Save Kishy-nivas/0bffbddcb3a4735aa741e36cbf1b24b0 to your computer and use it in GitHub Desktop.
Save Kishy-nivas/0bffbddcb3a4735aa741e36cbf1b24b0 to your computer and use it in GitHub Desktop.
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