Skip to content

Commit ac935a0

Browse files
committed
[Leo] 7th Week solutions (last question)
1 parent 1d067d2 commit ac935a0

File tree

1 file changed

+12
-0
lines changed
  • validate-binary-search-tree

1 file changed

+12
-0
lines changed

validate-binary-search-tree/Leo.py

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

0 commit comments

Comments
 (0)