Python | Runtime beats 98.34%, Memory beats 58.49%
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```python3 []\nclass ListNode:\n    def __init__(self, val=0, next=None):\n        self.val = val\n        self.next = next\n\nclass Solution:\n    def modifiedList(self, nums, head: ListNode) -> ListNode:\n        # Convert nums to a set for O(1) lookups\n        to_delete = set(nums)\n        \n        # Create a dummy node that points to the head of the list\n        dummy = ListNode(0)\n        dummy.next = head\n        \n        # Use two pointers: current to iterate and prev to manage the deletion\n        prev = dummy\n        current = head\n        \n        while current:\n            if current.val in to_delete:\n                # Skip the node to be deleted\n                prev.next = current.next\n            else:\n                # Move prev to current\n                prev = current\n            \n            # Move to the next node\n            current = current.next\n        \n        # Return the modified list, which is next of dummy\n        return dummy.next\n\n```
['Python3']