30:00
Find the lowest common ancestor (LCA) of two nodes in a binary tree. The LCA is the lowest node that has both p and q as descendants.
The number of nodes is in the range [2,105][2, 10^5][2,105].
−109≤Node.val≤109-10^9 \leq \text{Node.val} \leq 10^9−109≤Node.val≤109
All Node.val are unique.
Node.val
p != q
p and q will exist in the tree.
p
q
Finding LCA of nodes with values 5 and 1
-
3
5
1
6
2
0
8
7
4