Python DFS Solution

  • 0
    class Solution(object):
        def isValidBST(self, root):
            return self.isValid(root, None, None)
        def isValid(self, root, min_c, max_c):
            if root == None:
                return True
            if (min_c != None and root.val <= min_c) or (max_c != None and root.val >= max_c):
                return False
            return self.isValid(root.left, min_c, root.val) and self.isValid(root.right, root.val, max_c)

Log in to reply

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