Python Solution using Dummy Node
Intuition\nThe problem requires removing all nodes from the linked list whose values exist in a given list, nums. A direct traversal through the linked list is 
# Intuition\nThe problem requires removing all nodes from the linked list whose values exist in a given list, nums. A direct traversal through the linked list is necessary to identify and remove the required nodes. Since the removal of nodes could affect the head of the list, using a dummy node simplifies the logic and ensures that edge cases, like deleting the head, are handled smoothly.\n\n\nHere\'s the breakdown of the dummy node solution with detailed explanations for each section:\n\n\n# Approach\n1. Dummy Node: Create a dummy node that points to the original head of the linked list. This dummy node will help in cases where the head itself needs to be removed.\n\n2. Set for Lookup: Convert the list nums into a set (nums_set) to allow O(1) lookup for checking whether a node\'s value is in nums.\n\n3. Traversal: Use a current pointer, initialized to the dummy node. Traverse the list from this pointer and check if the next node\'s value exists in nums_set.\n\n4. If it does, skip the node by adjusting the next pointer to bypass it.\nIf it doesn\'t, move the current pointer to the next node.\n5. Return Modified List: After the traversal, return dummy.next, which points to the head of the modified list (this handles cases where the original head was removed).\n\n\n\n# Complexity\n- Time complexity: O(n + m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def modifiedList(self, nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:\n        nums = set(nums)\n        dummy = ListNode(0)\n        dummy.next = head\n        curr = dummy\n        while curr.next:\n            if curr.next.val in nums:\n                curr.next = curr.next.next\n            else:\n                curr = curr.next\n        return dummy.next\n\n        \n```
['Linked List', 'Python', 'Python3']