Untitled

 avatar
unknown
plain_text
a year ago
387 B
4
Indexable
import sys

class Solution(object):
    def isValidBST(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        def isBST(node, l, r):
            if node:
                return l < node.val < r and isBST(node.left, l, node.val) and isBST(node.right, node.val, r)
            return True
        return isBST(root, -sys.maxint, sys.maxint)
        
Editor is loading...
Leave a Comment