Simple Approach || Easy Solution With Proper Explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires us to remove nodes from a linked list if their values are present 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires us to remove nodes from a linked list if their values are present in a given list of numbers. The first thought is to traverse the linked list while maintaining pointers to the current and previous nodes. If the current node\'s value exists in the given list, we remove it by updating the previous node\'s next pointer.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use a set (or unordered set) to store all elements from the `nums` vector for fast lookup.\n2. Create a dummy node that points to the head of the list to handle edge cases, such as when the head node needs to be removed.\n3. Initialize two pointers, `prev` pointing to the dummy node and `curr` pointing to the head of the list.\n4. Traverse the linked list:\n   - If the current node\'s value is in the set, adjust the `prev` node\'s `next` pointer to skip the current node.\n   - Otherwise, move the `prev` pointer to the current node.\n   - Move the `curr` pointer to the next node.\n5. Return the modified list starting from the node after the dummy node.\n\n# Complexity\n- **Time complexity:**  \n  The time complexity is $$O(n + m)$$, where `n` is the number of nodes in the linked list, and `m` is the size of the `nums` vector. The set lookup and insertion operations are on average $$O(1)$$, and traversing the list is $$O(n)$$.\n\n- **Space complexity:**  \n  The space complexity is $$O(m)$$, where `m` is the size of the `nums` vector, due to storing the values in the set.\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\n        int n = nums.size();\n        set<int> st;\n        for (int i = 0; i < n; i++) {\n            st.insert(nums[i]);\n        }\n\n        ListNode* dummyNode = new ListNode(-1);\n        dummyNode->next = head;\n        ListNode* prev = dummyNode;\n        ListNode* temp = head;\n\n        while (temp != nullptr) {\n            if (st.find(temp->val) != st.end()) {\n\n                prev->next = temp->next;// skip the current node\n                temp = temp->next;\n            } else {\n                prev = temp;//update previous node when current node is not present in set\n                temp = temp->next;\n            }\n        }\n        return dummyNode->next;\n    }\n};
['Hash Table', 'C++']