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

Function dfs

javascript/1325-delete-leaves-with-a-given-value.js:18–26  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

16 */
17var removeLeafNodes = function (root, target) {
18 const dfs = (node) => {
19 if (!node) return null;
20 node.left = dfs(node.left);
21 node.right = dfs(node.right);
22 if (!node.left && !node.right) {
23 if (node.val === target) return null;
24 }
25 return node;
26 };
27
28 return dfs(root);
29};

Callers 1

removeLeafNodesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected