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

Function dfs

javascript/0872-leaf-similar-trees.js:18–27  ·  view source on GitHub ↗
(node, arr)

Source from the content-addressed store, hash-verified

16 */
17var leafSimilar = function (root1, root2) {
18 const dfs = (node, arr) => {
19 if (!node.left && !node.right) {
20 arr.push(node.val);
21 return arr;
22 }
23 if (node.left) dfs(node.left, arr);
24 if (node.right) dfs(node.right, arr);
25
26 return arr;
27 };
28
29 const arr1 = dfs(root1, []);
30 const arr2 = dfs(root2, []);

Callers 1

leafSimilarFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected