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 4aa739c commit fe26eb0Copy full SHA for fe26eb0
validate-binary-search-tree/doh6077.py
@@ -0,0 +1,10 @@
1
+class Solution:
2
+ def isValidBST(self, root: Optional[TreeNode]) -> bool:
3
+ def validate(node: Optional[TreeNode], low: float, high: float) -> bool:
4
+ if not node:
5
+ return True
6
+ if not (low < node.val < high):
7
+ return False
8
+ return (validate(node.left, low, node.val) and
9
+ validate(node.right, node.val, high))
10
+ return validate(root, float('-inf'), float('inf'))
0 commit comments