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

Function isSameTree

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

Source from the content-addressed store, hash-verified

123};
124
125function isSameTree(root, subRoot) {
126 if (!root && !subRoot) {
127 return true;
128 } else if (!root || !subRoot) {
129 return false;
130 } else if (root.val !== subRoot.val) {
131 return false;
132 }
133
134 const leftRes = isSameTree(root.left, subRoot.left);
135 const rightRes = isSameTree(root.right, subRoot.right);
136
137 return leftRes && rightRes;
138}

Callers 1

isSubtreeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected