MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / isValidBST

Function isValidBST

JavaScript/98.Validate-Binary-Search-Tree.js:32–52  ·  view source on GitHub ↗
(
  root,
  lower = Number.MIN_SAFE_INTEGER,
  upper = Number.MAX_SAFE_INTEGER
)

Source from the content-addressed store, hash-verified

30 */
31
32var isValidBST = function (
33 root,
34 lower = Number.MIN_SAFE_INTEGER,
35 upper = Number.MAX_SAFE_INTEGER
36) {
37 if (!root) return true;
38
39 let value = root.val;
40 if (value <= lower || value >= upper) {
41 return false;
42 }
43
44 if (!isValidBST(root.right, value, upper)) {
45 return false;
46 }
47
48 if (!isValidBST(root.left, lower, value)) {
49 return false;
50 }
51 return true;
52};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected