We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5378f08 commit c01c8e9Copy full SHA for c01c8e9
1 file changed
BST_Validator/main.py
@@ -0,0 +1,30 @@
1
+import sys
2
+
3
+class Node:
4
+ def __init__(self,value=None):
5
+ self.value=value
6
+ self.left_child=None
7
+ self.right_child=None
8
9
+def validate_bst(root,min=-sys.maxsize,max=sys.maxsize):
10
+ if root==None:
11
+ return True
12
+ if (root.value>min and
13
+ root.value<max and
14
+ validate_bst(root.left_child,min,root.value) and
15
+ validate_bst(root.right_child,root.value,max)):
16
17
+ else:
18
+ return False
19
20
+root=Node(5)
21
+l1=Node(4)
22
+r1=Node(6)
23
+r2=Node(10)
24
25
+r1.right_child=r2
26
27
+root.left_child=l1
28
+root.right_child=r1
29
30
+print(validate_bst(root))
0 commit comments