5 lines python recursion solution


  • 1
    X
    class Solution(object):
        def inorderSuccessor(self, root, p):
    
            if not root:
                return None
            if root.val <= p.val:
                return self.inorderSuccessor(root.right,p)
            return self.inorderSuccessor(root.left,p) or root
    

Log in to reply
 

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