#236 - Lowest Common Ancestor of a Binary Tree
Given a binary tree and two nodes p and q, find their lowest common ancestor (LCA). The LCA is the deepest node that is an ancestor of both p and q (a node can be an ancestor of itself).
| Input | Output |
|---|---|
root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 | 3 |
root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4 | 5 |
root = [1,2], p = 1, q = 2 | 1 |