💯Faster✅💯Less Mem✅🧠Detailed Approach🎯Linked List 🔥C++😎
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\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        // Create a set to store values from nums for quick lookup\n        set<int> s;\n        \n        // Insert each element from nums into the set\n        for (auto i : nums) {\n            s.insert(i);\n        }\n\n        // Initialize pointers to traverse the linked list\n        ListNode *curr = head;\n        ListNode *prev = nullptr;\n\n        // Traverse the linked list\n        while (curr != nullptr) {\n            // Check if the current node\'s value is in the set\n            if (s.find(curr->val) != s.end()) {\n                // If it is, we need to remove this node\n                if (prev == nullptr) {\n                    // If prev is null, we are at the head of the list\n                    // Update the head to the next node\n                    head = curr->next;\n                } else {\n                    // Otherwise, link the previous node to the next node\n                    prev->next = curr->next;\n                }\n                // Move to the next node\n                curr = curr->next;\n            } else {\n                // If the current node\'s value is not in the set\n                // Move both prev and curr forward\n                prev = curr;\n                curr = curr->next;\n            }\n        }\n        // Return the modified head of the list\n        return head;\n    }\n};\n```
['C++']