Skip to content

Commit b5f6c1b

Browse files
authored
Merge pull request vJechsmayr#350 from LenartBucar/master
Closes vJechsmayr#344
2 parents 3b287eb + 49ff5da commit b5f6c1b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
8+
class Solution:
9+
def isValidBST(self, root: TreeNode, sm=[], gt=[]) -> bool:
10+
if root is None:
11+
return True
12+
13+
if any([root.val <= x for x in sm]) or any([root.val >= x for x in gt]):
14+
return False
15+
16+
return (root.left is None or self.isValidBST(root.left, sm, gt + [root.val])) and (root.right is None or self.isValidBST(root.right, sm + [root.val], gt))

0 commit comments

Comments
 (0)