We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 37fbb8c commit a104fa5Copy full SHA for a104fa5
1 file changed
validate-binary-search-tree/Cyjin-jani.js
@@ -0,0 +1,23 @@
1
+const isValidBST = function (root) {
2
+ let answer = true;
3
+
4
+ function validateRecursion(node, min, max) {
5
+ if (!node) return;
6
7
+ if (node.val >= max || node.val <= min) {
8
+ answer = false;
9
+ return;
10
+ }
11
+ if (node.val <= min || node.val >= max) {
12
13
14
15
16
+ validateRecursion(node.left, min, node.val);
17
+ validateRecursion(node.right, node.val, max);
18
19
20
+ validateRecursion(root, -Infinity, Infinity);
21
22
+ return answer;
23
+};
0 commit comments