Lowest Common Ancestor of a Binary Tree III
Problem
Each node has a parent pointer. Given two nodes p and q, return their lowest common ancestor.
Input / Output
- Input: two tree nodes
pandq, each with aparentpointer. - Output: the lowest node that is an ancestor of both.
Constraints
- Nodes are guaranteed to exist in the tree.
Example
- Analogous to finding the intersection node of two upward-linked lists that both end at the root.
added …