Skip to content

Commit 392482c

Browse files
committed
BST validation exercise
1 parent ed5f7bc commit 392482c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

27. validate-bst.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def validateBst(node, less_than=float('inf'), greater_than=float('-inf')):
2+
if node is None:
3+
return True
4+
if greater_than <= node.value < less_than:
5+
left_validation = validateBst(node.left, node.value, greater_than)
6+
right_validation = validateBst(node.right, less_than, node.value)
7+
return left_validation and right_validation
8+
return False

0 commit comments

Comments
 (0)