Short python solution

  • 0
    class Solution(object):
        def lowestCommonAncestor(self, root, p, q):
            if not root:
                return None
            if root is p or root is q:
                return root
            if p.val < root.val < q.val or q.val < root.val < p.val:
                return root
            if p.val < root.val:
                return self.lowestCommonAncestor(root.left, p, q)
                return self.lowestCommonAncestor(root.right, p, q)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.