Explained Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Create a hash that s
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Create a hash that stores all the values of the array for time efficiency\n\n    - Create a hash (or a set) to store all the values in the array that need to be checked. This allows for efficient lookup in constant time, O(1), when determining whether a node\'s value exists in the array. This hash will help speed up comparisons as you iterate through the linked list.\n\n2. Create a previous node with a value of 0 and point it to the head, in case the head value exists in the array\n\n    - Set up a "dummy" node before the head of the linked list, initializing it with a placeholder value (e.g., 0). This dummy node will point to the head. This is useful because if the head node\u2019s value needs to be discarded, you can still adjust the list starting from the dummy node without losing the reference to the modified head. The dummy node simplifies list manipulation, especially at the start.\n3. Iterate through the node list and if the current value is equal to a value that exists in the array, discard it by pointing the previous node to the current\'s next node\n\n    - Traverse the linked list one node at a time. For each node, check if its value exists in the hash (i.e., it\'s a value that needs to be removed). If the current node\'s value is found in the hash, remove the node by making the previous node\u2019s next pointer skip the current node and point directly to the next node in the list. This effectively "deletes" the node by bypassing it. If the value is not found in the hash, simply move the previous node pointer to the current node and continue iterating.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```javascript []\nvar modifiedList = function(nums, head) {\n    //create a hash that stores all the values of the array for time efficiency\n    let hash = new Map();\n    for(let i=0; i<nums.length; i++) {\n        if(!hash.has(nums[i])) hash.set(nums[i], 1);\n    }\n\n    // create a previous node with a value 0 and point it to the head, in case head value exists in the array\n    let prev = new ListNode(0);\n    let list = head;\n    prev.next = head;\n    head = prev;\n\n    //iterate the node list and if the current value is equal to the value that exists in the array, discard it by pointing the previous value to the currents next\n    while(list) {\n        if(hash.has(list.val)) {\n            prev.next = list.next;\n            list = prev.next;\n        }\n        else {\n            prev = list;\n            list = list.next;\n        }\n    }\n\n    return head.next;\n};\n```\n``` cpp []\nclass Solution {\npublic:\n    ListNode* modifiedList(vector<int>& nums, ListNode* head) {\n\n        //create a hash that stores all the values of the array for time efficiency\n        unordered_map<int, int> hash;\n        for(auto i: nums) {\n            hash[i] = 1;\n        }\n\n        // create a previous node with a value 0 and point it to the head, in case head value exists in the array\n        ListNode* list = head;\n        ListNode* prev = new ListNode(0);\n        prev->next = head;\n        head = prev;\n        //iterate the node list\n        while(list) {\n            // if the current value is equal to the value that exists in the array\n            if(hash.find(list->val) != hash.end()) {\n                //discard it by pointing the previous value to the currents next\n                prev->next = list->next;\n                list = prev->next;\n            } else {\n                prev = list;\n                list = list->next;\n            }\n        }\n        return head->next;\n    }\n};\n```\n``` python []\nclass Solution:\n    def modifiedList(self, nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:\n        #create a hash that stores all the values of the array for time efficiency\n        hash = {}\n        for i in nums:\n            if i not in hash:\n                hash[i] = 1\n        #create a previous node with a value 0 and point it to the head, in case head value exists in the array\n        temp = head\n        prev = ListNode(0)\n        prev.next = head\n        head = prev\n        #iterate the node list\n        while temp:\n            #if the current value is equal to the value that exists in the array\n            if temp.val in hash:\n                #discard it by pointing the previous value to the currents next\n                prev.next = temp.next\n                temp = prev.next\n            else:\n                prev = temp\n                temp = temp.next\n        return head.next\n```
['Array', 'Hash Table', 'Linked List', 'C++', 'Python3', 'JavaScript']