Untitled
unknown
plain_text
2 years ago
387 B
9
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