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

Function isSubtree

javascript/0572-subtree-of-another-tree.js:7–16  ·  view source on GitHub ↗
(root, subRoot)

Source from the content-addressed store, hash-verified

5 * @return {boolean}
6 */
7var isSubtree = function (root, subRoot) {
8 if (!root) return false;
9
10 if (isSame(root, subRoot)) return true;
11
12 const hasLeftTree = isSubtree(root.left, subRoot);
13 const hasRightTree = isSubtree(root.right, subRoot);
14
15 return hasLeftTree || hasRightTree;
16};
17
18const isSame = (root, subRoot) => {
19 const hasReachedEnd = !(root && subRoot);

Callers

nothing calls this directly

Calls 4

hashifyFunction · 0.85
isSameFunction · 0.70
searchFunction · 0.70
isSameTreeFunction · 0.70

Tested by

no test coverage detected