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

Function isSame

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

Source from the content-addressed store, hash-verified

16};
17
18const isSame = (root, subRoot) => {
19 const hasReachedEnd = !(root && subRoot);
20 if (hasReachedEnd) return root === subRoot;
21
22 const isMismatch = root.val !== subRoot.val;
23 if (isMismatch) return false;
24
25 const isLeftSame = isSame(root.left, subRoot.left);
26 const isRightSame = isSame(root.right, subRoot.right);
27
28 return isLeftSame && isRightSame;
29};
30
31const hash = (val) =>
32 require('crypto').createHash('md5').update(val).digest('hex');

Callers 1

isSubtreeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected