[Python3] dfs O(N)
Algo\nTraverse the tree and remove nodes in to_delete. \n\nImplementation\n\nclass Solution:\n    def delNodes(self, root: TreeNode, to_delete: List[int]) -> Li
**Algo**\nTraverse the tree and remove nodes in `to_delete`. \n\n**Implementation**\n```\nclass Solution:\n    def delNodes(self, root: TreeNode, to_delete: List[int]) -> List[TreeNode]:\n        to_delete = set(to_delete) # O(1) lookup \n        \n        def fn(node, pval):\n            """Return node upon deletion of required values."""\n            if not node: return \n            if node.val in to_delete: \n                node.left = fn(node.left, None)\n                node.right = fn(node.right, None)\n                return \n            else: \n                if not pval: ans.append(node)\n                node.left = fn(node.left, node.val)\n                node.right = fn(node.right, node.val)\n                return node \n        \n        ans = []\n        fn(root, None)\n        return ans \n```\n\n**Analysis**\nTime complexity `O(N)`\nSpace complexity `O(N)`
['Python3']