Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Definition for a binary tree node.
- class TreeNode(object):
- def __init__(self, x):
- self.val = x
- self.left = None
- self.right = None
- class Solution():
- def isValidBST(self, root):
- if root.val is None:
- return [float("inf"), -float("inf")]
- l = self.isValidBST(root.left)
- r = self.isValidBST(root.right)
- if not l or not r:
- return False
- if l[1] < root.val < r[0]:
- return [min(l[0], root.val), max(r[1], root.val)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement