You are viewing a single comment's thread. Return to all comments →
My Java 8 Solution
public static Node lca(Node root, int v1, int v2) { if (v1 > v2) { int temp = v1; v1 = v2; v2 = temp; } while (root != null) { if (v2 < root.data) { root = root.left; } else if (v1 > root.data) { root = root.right; } else { return root; } } return null; }
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
My Java 8 Solution