Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. # Definition for a binary tree node.
  2. class TreeNode(object):
  3. def __init__(self, x):
  4. self.val = x
  5. self.left = None
  6. self.right = None
  7.  
  8. class Solution():
  9. def isValidBST(self, root):
  10. if root.val is None:
  11. return [float("inf"), -float("inf")]
  12. l = self.isValidBST(root.left)
  13. r = self.isValidBST(root.right)
  14. if not l or not r:
  15. return False
  16. if l[1] < root.val < r[0]:
  17. return [min(l[0], root.val), max(r[1], root.val)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement