Simple python Solution beats 90% of the python users
\n# Problem Description:\nWe are given a linked list and a list of integers nums. The goal is to modify the linked list such that all nodes containing values pr
\n# Problem Description:\nWe are given a linked list and a list of integers nums. The goal is to modify the linked list such that all nodes containing values present in nums are removed from the list. The modified list should contain only nodes whose values are not in nums.\n\n# Hash Set for Fast Lookup:\n\nWe store the values from nums in a set to achieve O(1) lookup time. This helps in quickly determining whether a node\u2019s value is in nums or not.\n\n# Skipping Initial Invalid Nodes:\n\nWe start by handling edge cases where the initial nodes (including the head) are invalid. If the head node\u2019s value is in nums, we keep advancing the head to the next node until we find a valid node or reach the end of the list.\n# Iterating Through the List:\n\nOnce the head is positioned at a valid node, we traverse the list using two pointers:\nprev keeps track of the last valid node.\ncurr is used to traverse the rest of the list.\nIf a node\u2019s value is not in nums, we connect it to the prev node; otherwise, it is skipped.\n\n# Ensuring Proper Termination:\n\nAfter processing all nodes, the last valid node\u2019s next pointer is set to None to mark the end of the modified list, avoiding dangling references.\n# Example:\nLet\u2019s walk through an example:\n\nInput:\nhead = [1, 2, 6, 3, 4, 5, 6]\nnums = [6, 3]\nOutput:\nThe modified list after removing all nodes containing values from nums will be [1, 2, 4, 5].\n\n# Complexity\n- # Time Complexity:\n  O(n): We traverse the list once, where n is the number of nodes in the linked list. This ensures efficient processing.\n\n- Space complexity:\n O(n)\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\n\n\nclass Solution:\n    def modifiedList(self, nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:\n        s = set(nums)\n        \n        while head and head.val in s:\n            head = head.next\n        \n      \n        if not head:\n            return None\n\n        prev = head\n        curr = head.next\n        \n        while curr:\n            if curr.val not in s:\n                prev.next = curr\n                prev = curr\n            curr = curr.next\n        \n        prev.next = None\n        return head\n\n        \n```
['Array', 'Hash Table', 'Linked List', 'Python3']