← 返回 atlassian 的题目列表Lowest Common Ancestor Variant
类型:online_judge
Given a binary tree and two nodes, find their lowest common ancestor. This is a variant of the Lowest Common Ancestor (LCA) problem. Please write a function to implement this functionality.
Example
Input
root = TreeNode(3)
root.left = TreeNode(5)
root.right = TreeNode(1)
p = root.left # TreeNode(5)
q = root.right # TreeNode(1)
Output
3