Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Lowest Common Ancestor

Go down

Lowest Common Ancestor Empty Lowest Common Ancestor

Post  yangwenzhou Wed Oct 12, 2011 8:24 pm

Node LCA(Node root, Node p, Node q){
if(root==null)
return null;
if(root==p||root==q)
return root;
Node left=LCA(root.left, p, q);
Node right=LCA(root.right, p, q);
if(left!=null&&right!=null)
return root;
return left!=null?left:right;
}

yangwenzhou

Posts : 5
Join date : 2011-09-23

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum