Python solution, without using maxint, minint and inorder traversal


  • 0
    class Solution(object):
        def helper(self, root):
            if root == None: return True, None, None
            reL, ll, lr = self.helper(root.left)
            if not reL: return False, None, None
            if lr != None and lr >= root.val: return False, None, None
            reR, rl, rr = self.helper(root.right)
            if not reR: return False, None, None
            if rl != None and rl <= root.val: return False, None, None
            if ll == None: ll = root.val
            if rr == None: rr = root.val
            return True, ll, rr
        
        def isValidBST(self, root):
            return self.helper(root)[0]
    

Log in to reply
 

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