Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
387 B
1
Indexable
Never
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)
        
Leave a Comment