1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { int x = root.val; if (p.val < x && q.val < x) return lowestCommonAncestor(root.left, p, q); if (p.val > x && q.val > x) return lowestCommonAncestor(root.right, p, q); return root; } }
|