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

Function dfs

javascript/1448-Count-Good-Nodes-in-Binary-Tree.js:20–28  ·  view source on GitHub ↗
(root, max, total)

Source from the content-addressed store, hash-verified

18}
19
20const dfs = (root, max, total) => {
21 const isGood = max <= root.val
22 if (isGood) total[0]++;
23
24 max = Math.max(max, root.val);
25
26 count(root.left, max, total);
27 count(root.right, max, total);
28}
29
30/**
31 * https://leetcode.com/problems/count-good-nodes-in-binary-tree/

Callers 1

countFunction · 0.70

Calls 1

countFunction · 0.70

Tested by

no test coverage detected