Skip to content

Commit fe26eb0

Browse files
committed
Validate Binary Search Tree Solution
1 parent 4aa739c commit fe26eb0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def isValidBST(self, root: Optional[TreeNode]) -> bool:
3+
def validate(node: Optional[TreeNode], low: float, high: float) -> bool:
4+
if not node:
5+
return True
6+
if not (low < node.val < high):
7+
return False
8+
return (validate(node.left, low, node.val) and
9+
validate(node.right, node.val, high))
10+
return validate(root, float('-inf'), float('inf'))

0 commit comments

Comments
 (0)