Python | DFS
Basic Idea\n the node to be deleted can either be\n\t leaf node - nothing has to be done in this case\n\t subtree rooted at node - so during dfs we need to info
Basic Idea\n* the node to be deleted can either be\n\t* leaf node - nothing has to be done in this case\n\t* subtree rooted at node - so during dfs we need to inform its left and right child, that the parent has been deleted, and they are now roots, this is the only extra information we need to pass during our regular dfs\n\t\t* when this root, has been deleted, when we traverse to its, children, the isroot marker will be true, and we will append it to our resultant list\n\n* converted, to_delete to set, to get O(1) access\n\n```\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n    def delNodes(self, root: TreeNode, to_delete: List[int]) -> List[TreeNode]:\n        res = []\n        to_delete = set(to_delete)\n        def helper(node, isroot):\n            if not node:\n                return \n           \n            nodeDel = node.val in to_delete\n            if isroot and not nodeDel:\n                res.append(node)\n                \n            node.left = helper(node.left,nodeDel)\n            node.right = helper(node.right, nodeDel)\n            return None if nodeDel else node\n        \n        helper(root, True)\n        # print(len(res))\n        return res\n        \n```
['Stack', 'Depth-First Search', 'Python']