Python BFS with Explaination
Please Upvote if you like the solution \n\n# Definition for a binary tree node.\n# class TreeNode(object):\n#     def __init__(self, val=0, left=None, right=Non
Please Upvote if you like the solution \n```\n# Definition for a binary tree node.\n# class TreeNode(object):\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution(object):\n    def delNodes(self, root, to_delete):\n        """\n        :type root: TreeNode\n        :type to_delete: List[int]\n        :rtype: List[TreeNode]\n        """\n        to_delete = set(to_delete)\n        queue = deque()\n        queue.append((root, False))\n        result = []\n        \n        while queue:\n            \n            node, parentAlive = queue.popleft()\n            \n            #Adding only the ones who doesnt have a parent and not in delete \n            # because if the parent hasnt been deleted then the node has already been added to result beacuse of the parent\n            if node.val not in to_delete and not parentAlive:\n                result.append(node)\n            \n            \n            # Doing this to determine if the next node has a paren or the parent has been marked to be deleted \n            if node.val not in to_delete:\n                parentAlive = True \n            else:\n                parentAlive = False\n            \n            if node.left:\n                queue.append((node.left, parentAlive))\n                if node.left.val in to_delete:\n                    node.left = None\n            \n            if node.right:\n                queue.append((node.right, parentAlive))\n                if node.right.val in to_delete:\n                    node.right = None\n        return result \n                    \n                \n                \n                    \n                \n                \n                \n                \n        \n        \n        \n```
['Python']