Lowest Common Ancestor

View previous topic View next topic Go down

Lowest Common Ancestor

Post  yangwenzhou on 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

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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