Easy Solution With Explanation in C++ using map
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n1. Map Creation: \n  
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n1. **Map Creation**: \n   - A `map<int, int>` is used to store the values from the `nums` vector. Each value in `nums` is mapped to `1` to mark it as "to be deleted" if found in the linked list.\n   \n2. **Iterating the Linked List**:\n   - A pointer `temp` is used to traverse the linked list, and `prev` is used to keep track of the previous node.\n   - For each node, the value (`temp->val`) is checked in the map.\n   \n3. **Node Deletion**:\n   - If the current node\'s value exists in the map (`mpp[data] == 1`), the node is deleted.\n   - If the node is the head, the head is moved to the next node.\n   - Otherwise, the `prev->next` is updated to skip the current node.\n   - After deletion, the memory is freed using `delete`.\n\n4. **Return the New Head**:\n   - The function returns the potentially modified head of the linked list.\n\n# Complexity\n- **Time complexity:**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- **O(n + m)** where `n` is the length of the `nums` vector and `m` is the number of nodes in the linked list. We iterate over the vector and linked list once each.\n\n- **Space complexity:**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n- **O(n)** because of the map used to store the values from the `nums` vector.\n\n# Code\n```cpp []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* modifiedList(vector<int>& nums, ListNode* head) {\n        map<int , int> mpp;\n\n        for(auto i : nums){\n            mpp[i] = 1;\n        }\n\n        ListNode* prev = head;\n        ListNode* temp = head;\n\n        while(temp){\n            int data = temp->val;\n            if(mpp[data] == 1){\n                if(temp == head){\n                    head = temp->next;\n                    ListNode *del = temp;\n                    temp = temp->next;\n                    delete del;\n                }\n                else{\n                    prev->next = temp->next;\n                    ListNode* del = temp;\n                    temp = temp->next;\n                    delete del;\n                }\n            }\n            else{\n                prev = temp;\n                temp = temp->next;\n            }\n           \n        }\n\n        return head;\n    }\n};\n```
['Array', 'Hash Table', 'Linked List', 'C++']