[typescript/javascript] easy DFS solution w/ comments
\nfunction delNodes(root: TreeNode | null, to_delete: number[]): Array<TreeNode | null> {\n    // create set of to_delete for o(1) lookups\n    const toDelete =
```\nfunction delNodes(root: TreeNode | null, to_delete: number[]): Array<TreeNode | null> {\n    // create set of to_delete for o(1) lookups\n    const toDelete = new Set(to_delete);\n    // result list\n    const res: (TreeNode | null)[] = [];\n\n    // helper dfs method to prune tree and add to set\n    function dfs(node: TreeNode | null, isRoot: boolean): TreeNode | null {\n        // base case\n        if (!node) return null;\n\n        // check if this node should be pruned\n        const deleted = toDelete.has(node.val);\n\n        // check if root and shouldn\'t be deleted\n        if (isRoot && !deleted) res.push(node);\n\n        // build left and right subtrees, left and right will be ROOTS if this was deleted\n        node.left = dfs(node.left, deleted);\n        node.right = dfs(node.right, deleted);\n\n        // if this one was pruned, return null, if not, return this node\n        return deleted ? null : node;\n    }\n\n    // start dfs pruning\n    dfs(root, true);\n\n    return res;\n}\n```\n
['TypeScript', 'JavaScript']