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 949e83e commit f322c64Copy full SHA for f322c64
validate-binary-search-tree/JangAyeon.js
@@ -0,0 +1,28 @@
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
+const dfs = (node, left, right) => {
14
+ if (!node) {
15
+ return true;
16
+ }
17
+
18
+ return (
19
+ node.val > left &&
20
+ node.val < right &&
21
+ dfs(node.left, left, node.val) &&
22
+ dfs(node.right, node.val, right)
23
+ );
24
+};
25
26
+const isValidBST = function (root) {
27
+ return dfs(root, -Infinity, Infinity);
28
0 commit comments