MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / isValidBST

Function isValidBST

javascript/0098-validate-binary-search-tree.js:7–15  ·  view source on GitHub ↗
(root, min = -Infinity, max = Infinity)

Source from the content-addressed store, hash-verified

5 * @return {boolean}
6 */
7var isValidBST = function (root, min = -Infinity, max = Infinity) {
8 const isBaseCase = root === null;
9 if (isBaseCase) return true;
10
11 const isInvalid = root.val <= min || max <= root.val;
12 if (isInvalid) return false;
13
14 return dfs(root, min, max);
15};
16
17const dfs = (root, min, max) => {
18 const left = isValidBST(root.left, min, root.val);

Callers 1

dfsFunction · 0.70

Calls 3

dfsFunction · 0.70
moveLeftFunction · 0.70
popMethod · 0.45

Tested by

no test coverage detected