Beats 98% users... Give it a try
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\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# Definition for a binary tree node.\n\n# class TreeNode:\n\n#     def __init__(self, val=0, left=None, right=None):\n\n#         self.val = val\n\n#         self.left = left\n\n#         self.right = right\n\nclass Solution:\n\n    def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]:\n\n        result = []\n\n        def dfs(parent: Optional[TreeNode], node: Optional[TreeNode]):\n\n            nonlocal result\n\n            if not node:\n\n                return\n\n            if node.val in to_delete:\n\n                if parent:\n\n                    if parent.left == node:\n\n                        parent.left = None\n\n                    else:\n\n                        parent.right = None\n\n                dfs(None, node.left)\n\n                dfs(None, node.right)\n\n            else:\n\n                if not parent:\n\n                    result.append(node)\n\n                dfs(node, node.left)\n\n                dfs(node, node.right)\n\n        dfs(None, root)\n\n        return result\n\n            \n\n\n      \n```
['Array', 'Hash Table', 'Tree', 'Depth-First Search', 'C', 'Binary Tree', 'Python', 'C++', 'Java', 'Python3']