Lowest Common Ancestor
Join the DZone community and get the full member experience.
Join For Freepublic static Node getLCANode(Node root, int key1, int key2) { if (root == null) { return null; } if (key1 > root.key && key2 > root.key) { return getLCANode(root.rightNode,key1,key2); } if (key1 < root.key && key2 < root.key) { return getLCANode(root.leftNode,key1,key2); } else { return root; } }
Opinions expressed by DZone contributors are their own.
Comments