Python recursive

  • 0
    class Solution(object):
        def lowestCommonAncestor(self, root, p, q):
            v1, v2 = min(p.val, q.val), max(p.val, q.val)
            if v1 <= root.val <= v2:
                return root
            if v1 > root.val:
                return self.lowestCommonAncestor(root.right, p, q)
            return self.lowestCommonAncestor(root.left, p, q)

Log in to reply

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