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

Function dfs

javascript/0129-sum-root-to-leaf-numbers.js:18–27  ·  view source on GitHub ↗
(node, num)

Source from the content-addressed store, hash-verified

16var sumNumbers = function (root) {
17 let total = 0;
18 const dfs = (node, num) => {
19 if (!node.left && !node.right) {
20 num = num + node.val;
21 total += +num;
22 return;
23 }
24
25 node.left && dfs(node.left, num + node.val);
26 node.right && dfs(node.right, num + node.val);
27 };
28
29 dfs(root, '');
30 return total;

Callers 1

sumNumbersFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected