Skip to content

Commit 6777e91

Browse files
authored
Update Validate-Binary-Search-Tree.py
1 parent 7dbdbf0 commit 6777e91

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Leetcode/Validate-Binary-Search-Tree.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,19 @@ def check(node, left_limit, right_limit):
1919
return check(node.left, left_limit, node.val) and check(node.right, node.val, right_limit)
2020
return False
2121
return check(root, -1*float("inf"), float("inf"))
22+
23+
"""
24+
if root == None:
25+
return True
26+
27+
def is_bst_helper(root, left_val, right_val):
28+
if root == None:
29+
return True
30+
31+
if root.val <= left_val or root.val >= right_val:
32+
return False
33+
34+
return is_bst_helper(root.left, left_val, root.val) and is_bst_helper(root.right, root.val, right_val)
35+
36+
return is_bst_helper(root, float("-inf"), float("inf"))
37+
"""

0 commit comments

Comments
 (0)