Best optimal approach 100%
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```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        if(head==NULL){\n            return 0;\n        }\n        int n = nums.size();\n        // for(int i = 0; i<n; i++){\n        //     if(nums[i]==head->val){\n        //         ListNode* temp = head;\n        //         head = head->next;\n        //         delete(temp);\n        //     }\n        // }\n        // return head;\n        unordered_set<int> st(nums.begin(), nums.end());\n        while(head!=NULL && st.find(head->val)!=st.end()){\n            ListNode* temp = head;\n            head = head->next;\n            delete(temp);\n        }\n        ListNode* curr = head;\n        while(curr!=NULL && curr->next!=NULL){\n            if(st.find(curr->next->val)!=st.end()){\n                ListNode* temp = curr->next;\n                curr->next = curr->next->next;\n                delete(temp);\n            } else {\n                curr = curr->next;\n            }\n        }\n        return head;\n    }\n};\n```
['C++']