Skip to content

Commit bbb73a4

Browse files
committed
validate binary search tree solved
1 parent 9bf3c3b commit bbb73a4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public boolean isValidBST(TreeNode root) {
3+
if(root==null||(root.left==null&&root.right==null)) return true;
4+
return isvalid(root,Long.MIN_VALUE,Long.MAX_VALUE);
5+
}
6+
public boolean isvalid(TreeNode root,long min,long max)
7+
{
8+
if(root==null) return true;
9+
if(root.val<=min||root.val>=max) return false;
10+
return isvalid(root.left,min,root.val)&&isvalid(root.right,root.val,max);
11+
}
12+
}
13+

0 commit comments

Comments
 (0)