Python simple solution


  • 0
    G

    Python simple solution:

    class Solution(object):
        def lowestCommonAncestor(self, root, p, q):
            if q.val<p.val:
                return self.lowestCommonAncestor(root,q,p)
            if p.val<=root.val<=q.val:
                return root
            elif q.val<root.val:
                return self.lowestCommonAncestor(root.left,p,q)
            else:
                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.