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

Function dfs

javascript/0543-diameter-of-binary-tree.js:20–30  ·  view source on GitHub ↗
(root, max)

Source from the content-addressed store, hash-verified

18};
19
20const dfs = (root, max) => {
21 const left = diameterOfTree(root.left, max);
22 const right = diameterOfTree(root.right, max);
23
24 const diameter = left + right;
25 max[0] = Math.max(max[0], diameter);
26
27 const height = Math.max(left, right);
28
29 return height + 1;
30};

Callers 1

diameterOfTreeFunction · 0.70

Calls 1

diameterOfTreeFunction · 0.85

Tested by

no test coverage detected