Easy 5 Language || Beats Everyone || Set
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nComplexityComplexit Describe y# Algorithm (Spoiler \uD83D\uDEA8)\n(You sh
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nComplexityComplexit Describe y# Algorithm (Spoiler \uD83D\uDEA8)\n(You should first try yourself)\n1.Initialize a set valuesToRemove and populate it with the values of the nums array.\n2.While the head of the linked list is not null and the head\'s value is present in valuesToRemove:\n3.Move head to head.next.\n4.If the head is null, return null since all nodes have been removed.\n5.Start iterating from the head of the modified list:\n6.For each node current, check if the value of the next node (current.next) is in the valuesToRemove set.\n7.If it is, skip the next node by updating current.next to current.next.next\n8.If it is not, move the current pointer to the next node in the list.\nReturn the updated head of the list.our approach to solving the problem. \n\n# CoComplexitymplexity\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        unordered_set<int>s;\n        for(auto x:nums) s.insert(x);\n        ListNode* newHead= new ListNode(-1);\n        ListNode* temp=newHead;\n        while(head){\n            if(s.count(head->val)==0){\n                newHead->next=new ListNode(head->val);\n                newHead=newHead->next;\n            }\n            head=head->next;\n        }\n        return temp->next;\n    }\n};\n```
['Array', 'Hash Table', 'Linked List', 'C++', 'Java', 'Python3']