Easy recursive 5 line python solution, beats 80%

  • 0
    class Solution(object):
        def isValidBST(self, root, mini = float("-inf"), maxi = float("inf")):
            if not root:
                return True
            if root.val <= mini or root.val >= maxi:
                return False
            return self.isValidBST(root.left, mini, root.val) and self.isValidBST(root.right, root.val, maxi)

Log in to reply

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