0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
class Solution: def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': if root==None: return None if root.val > p.val and root.val > q.val: left = self.lowestCommonAncestor(root.left,p,q) return left elif root.val < p.val and root.val < q.val: right = self.lowestCommonAncestor(root.right,p,q) return right else: return root
|