Given a binary tree, find the lowest common ancestor (LCA) of two given nodes, p and q.
- The
rootof a binary tree. - Two target nodes
pandq.
Input: root = [3, 5, 1, 6, 2, 0, 8, null, null, 7, 4], p = 5, q = 1
Output: 3
Explanation: The LCA of nodes 5 and 1 is 3.