We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d551167 commit af9a5cfCopy full SHA for af9a5cf
validate-binary-search-tree/samthekorean.py
@@ -0,0 +1,16 @@
1
+# TC : O(n) where n being the number of nodes of the tree
2
+# SC : O(n) where n being the size of sum of every nodes
3
+class Solution:
4
+ def isValidBST(self, root: Optional[TreeNode]) -> bool:
5
+ def is_valid_bst(node, min_val, max_val):
6
+ if not node:
7
+ return True
8
+
9
+ if node.val <= min_val or node.val >= max_val:
10
+ return False
11
12
+ return is_valid_bst(node.left, min_val, node.val) and is_valid_bst(
13
+ node.right, node.val, max_val
14
+ )
15
16
+ return is_valid_bst(root, float("-inf"), float("inf"))
0 commit comments