Skip to content

Commit 232899d

Browse files
committed
validate binary search tree solution
1 parent 9286817 commit 232899d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 문제: https://leetcode.com/problems/validate-binary-search-tree/description/
3+
*
4+
* 요구사항:
5+
* root 이진 트리 구조가 주어졌을 때, 해당 트리가 유효한 BST인지 판별하라.
6+
*
7+
* * */
8+
9+
const isValidBST = (nums) => {
10+
const validate = (node, min, max) => {
11+
if (!node) return true;
12+
13+
if (node.val <= min || node.val >= max) return false;
14+
15+
return validate(node.left, min, node.val) &&
16+
validate(node.right, node.val, max);
17+
}
18+
19+
return validate(root, -Infinity, Infinity);
20+
}

0 commit comments

Comments
 (0)