Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 60dffde

Browse files
authored
Create Validate_BST.py
1 parent 53bca8d commit 60dffde

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def isValidBST(self, root: Optional[TreeNode]) -> bool:
3+
MIN = float('-inf')
4+
MAX = float('inf')
5+
def solve(root, MIN, MAX):
6+
if root is None:
7+
return True
8+
if root.val <= MIN or root.val >= MAX:
9+
return False
10+
return solve(root.left, MIN, root.val) and solve(root.right,root.val, MAX)
11+
return solve(root, MIN, MAX)

0 commit comments

Comments
 (0)