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 b7514ac commit b4e34deCopy full SHA for b4e34de
validate-binary-search-tree/reach0908.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
10
+ * @param {TreeNode} root
11
+ * @return {boolean}
12
13
+var isValidBST = function (root, low = -Infinity, high = Infinity) {
14
+ if (!root) {
15
+ return true;
16
+ }
17
+
18
+ if (root.val <= low || root.val >= high) {
19
+ return false;
20
21
22
+ return (
23
+ isValidBST(root.left, low, root.val) &&
24
+ isValidBST(root.right, root.val, high)
25
+ );
26
+};
0 commit comments