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

Method checkDescendants

javascript/1993-operations-on-tree.js:107–119  ·  view source on GitHub ↗

* Helper method to check descendants * Time O(n) | Space O(n) * @param {number} index * @return {boolean}

(index)

Source from the content-addressed store, hash-verified

105 * @return {boolean}
106 */
107 checkDescendants(index) {
108 const stack = [];
109 stack.push(index);
110 while (stack.length) {
111 const node = stack.pop();
112 const children = this.childHash[node];
113 for (let i = 0; i < (children && children.length); i++) {
114 if (this.treeHash[children[i]]) return true;
115 stack.push(children[i]);
116 }
117 }
118 return false;
119 }
120}

Callers 1

upgradeMethod · 0.95

Calls 2

pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected