Skip to content

Commit b88df03

Browse files
author
jinvicky
committed
validate binary search tree solution
1 parent c171ccc commit b88df03

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// dfs 방식으로 풀이해야 합니다. tree 관련 easy 문제를 10문제 정도 풀고 접근했습니다.
3+
class Solution {
4+
public boolean isValidBST(TreeNode root) {
5+
return check(root, Long.MIN_VALUE, Long.MAX_VALUE);
6+
}
7+
8+
private boolean check(TreeNode node, long min, long max) {
9+
if (node == null) return true;
10+
11+
if (!(node.val > min && node.val < max)) return false;
12+
13+
return check(node.left, min, node.val) && check(node.right, node.val, max);
14+
}
15+
}

0 commit comments

Comments
 (0)