Commented Python solution DFS (recursive)
Code\n```\n\nclass Solution:\n    def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]:\n        # really good explanation: http
# Code\n```\n\nclass Solution:\n    def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]:\n        # really good explanation: https://leetcode.com/problems/delete-nodes-and-return-forest/solutions/656106/python-recursive-clean-explained-in-details-with-tips-10-lines-fast/\n        res = []\n\n        # two types of nodes to be deleted: if root or if leaf\n        def dfs(root):\n            if root is None:\n                return None\n                \n            # don\'t iterate through to_delete, iterate through tree and see if that node\n            # is in to_delete and remove it. Since every node is unique this can be done.\n            root.left = dfs(root.left)\n            root.right = dfs(root.right)\n\n            # post order: if the check below is after root.left = ... and root.right = ... calls, we make sure that the leaf\n            # nodes are processed first\n\n            if root.val in to_delete: # lookup is now O(1) cuz set\n                # if leaf node\n                if root.left is None and root.right is None:\n                    return None # assign root.left of calling node as None\n                else:\n                    # non-leaf (root) node, collect subtrees that were attached to this root node\n                    if root.left:\n                        res.append(root.left)\n                    if root.right:\n                        res.append(root.right)\n                    return None\n            \n            # else the node is not be deleted, just return the node as it is to whoever called it\n            return root\n        \n\n        to_delete = set(to_delete)\n        # get the remanining tree and append it to res\n        node = dfs(root)\n        if node:\n            res.append(node)\n        return res\n
['Tree', 'Depth-First Search', 'Binary Tree', 'Python', 'Python3']