[Python] 2 solutions - Clean & Concise
\u2714\uFE0F Solution 1: Delete Parent Pointer\n- When processing the current root node\n\t- If root is in delete:\n\t\t- Delete the parent pointer to that node
**\u2714\uFE0F Solution 1: Delete Parent Pointer**\n- When processing the current `root` node\n\t- If `root` is in delete:\n\t\t- Delete the parent pointer to that node. (Set `p.left = None` if `p.left == root` or `p.right = None` if `p.right == root`)\n\t\t- Now the tree is split into leftTree and rightTree.\n\t\t- ans.append(dfs(root.left, root))\n\t\t- ans.append(dfs(root.right, root))\n```python\nclass Solution:\n    def delNodes(self, root: TreeNode, to_delete: List[int]) -> List[TreeNode]:\n        ans = []\n        deleteSet = set(to_delete)\n\n        def dfs(root, par):\n            if root == None: return None\n            if root.val in deleteSet:\n                if par != None and par.left == root:\n                    par.left = None\n                if par != None and par.right == root:\n                    par.right = None\n                left = dfs(root.left, root)\n                if left != None: \n                    ans.append(left)\n                right = dfs(root.right, root)\n                if right != None: \n                    ans.append(right)\n                return None\n            dfs(root.left, root)\n            dfs(root.right, root)\n            return root\n        \n        root = dfs(root, None)\n        if root != None:\n            ans.append(root)\n        return ans\n```\nComplexity:\n- Time: `O(N)`\n- Space: `O(N)`\n\n---\n**\u2714\uFE0F Solution 2: Add if current root is not deleted**\n- The idea is to add the current `root` if that current `root` is a root and it hasn\'t been deleted.\n```python\nclass Solution:\n    def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]:\n        toDeleteSet = set(to_delete)\n        ans = []\n        \n        def dfs(root, possibleRoot):\n            if root == None:\n                return None\n            \n            if root.val in toDeleteSet:\n                root.left = dfs(root.left, True)\n                root.right = dfs(root.right, True)\n                return None\n            else:\n                root.left = dfs(root.left, False)\n                root.right = dfs(root.right, False)\n                if possibleRoot:\n                    ans.append(root)\n                return root\n                \n        dfs(root, True)\n        return ans\n```\nComplexity:\n- Time: `O(N)`\n- Space: `O(N)`
[]