Loading problem…
Given a binary tree root and two node values p and q, return the value of their lowest common ancestor (LCA).
p
q
If one value does not exist in the tree, return null.
null
// Tree: // 3 // / \ // 5 1 // / \ / \ // 6 2 0 8 // / \ // 7 4 lowestCommonAncestor(root, 5, 1); // 3 lowestCommonAncestor(root, 5, 4); // 5
2 hints available with Pro