Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import inf
- def solution(root) -> bool:
- def dfs(root, min_val, max_val):
- if not root:
- return True
- if root.val <= min_val or root.val >= max_val:
- return False
- left = dfs(root.left, min_val, root.val)
- right = dfs(root.right, root.val, max_val)
- return left and right
- return dfs(root, -inf, inf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement