Easiest C++ / Python3 Solution -- Please upvote if you find this helpful
Intuition\n\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- Tim
# Intuition\n![Screenshot 2024-07-14 111633.png](https://assets.leetcode.com/users/images/cca0cbc0-a692-4804-bfb8-5817f2817685_1720936040.3664603.png)\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/**\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        if (head == nullptr) \n            return nullptr;\n    \n        unordered_set<int> apnaSet(nums.begin(), nums.end());\n        ListNode* dummy = new ListNode(0);\n        dummy->next = head;\n    \n        ListNode* prev = dummy;\n        ListNode* curr = head;\n    \n        while (curr != nullptr) {\n            if (apnaSet.count(curr->val) > 0) {\n                // Remove current node\n                prev->next = curr->next;\n                delete curr;\n                curr = prev->next; // Move curr to the next node (don\'t move prev)\n            } else {\n                // Move both pointers forward\n                prev = curr;\n                curr = curr->next;\n            }\n        }\n    \n         ListNode* result = dummy->next;\n         delete dummy;\n    \n         return result;\n         }\n};\n```
['Python', 'C++', 'Java', 'Python3']