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

Function removeLeafNodes

javascript/1325-delete-leaves-with-a-given-value.js:17–29  ·  view source on GitHub ↗
(root, target)

Source from the content-addressed store, hash-verified

15 * @return {TreeNode}
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

nothing calls this directly

Calls 1

dfsFunction · 0.70

Tested by

no test coverage detected