python ugly solution with queue O(n^2)
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#         se
# 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#         self.right = right\nclass Solution:\n    def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]:\n\n        queue = deque()\n\n        def removeNode(parent, leftChild, rightChild, valToDelete):\n            if leftChild and leftChild.val == valToDelete:\n                parent.left = None\n                queue.append(leftChild.left)\n                queue.append(leftChild.right)\n                return True\n            elif rightChild and rightChild.val == valToDelete:\n                parent.right = None\n                queue.append(rightChild.left)\n                queue.append(rightChild.right)\n                return True\n            res = False\n            if leftChild:\n                res = res or removeNode(leftChild, leftChild.left, leftChild.right, valToDelete)\n            if rightChild:\n                res = res or removeNode(rightChild, rightChild.left, rightChild.right, valToDelete)\n            return res\n        \n        queue.append(root)\n        i = 0\n        while i < len(to_delete):\n            valToDelete = to_delete[i]\n            currRoot = queue.popleft()\n            if currRoot:\n                if currRoot.val == valToDelete:\n                    queue.append(currRoot.left)\n                    queue.append(currRoot.right)\n                    i += 1\n                else:\n                    if removeNode(currRoot, currRoot.left, currRoot.right, valToDelete):\n                        i += 1\n                    queue.append(currRoot)\n\n        return filter(lambda x: x, queue)\n```
['Python3']