Skip to content

Commit f17f3b8

Browse files
committed
Add validate binary search Solution - s0ooo0k
1 parent dda1a7d commit f17f3b8

File tree

1 file changed

+14
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)