Solution By Dare2Solve | Detailed Explanation | Clean Code
Explanation []\nauthorslog.vercel.app/blog/p5FUHDtSrA\n\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n    ListNode* modifiedList(vector<int>& nums, ListNode* 
```Explanation []\nauthorslog.vercel.app/blog/p5FUHDtSrA\n```\n\n# Code\n\n```cpp []\nclass Solution {\npublic:\n    ListNode* modifiedList(vector<int>& nums, ListNode* head) {\n        ListNode* res = new ListNode();\n        ListNode* resCur = res;\n        ListNode* cur = head;\n        unordered_set<int> set(nums.begin(), nums.end());\n        \n        while (cur) {\n            if (set.find(cur->val) == set.end()) {\n                resCur->next = new ListNode(cur->val);\n                resCur = resCur->next;\n            }\n            cur = cur->next;\n        }\n        \n        return res->next;\n    }\n};\n```\n\n```python []\nclass Solution:\n    def modifiedList(self, nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:\n        res = ListNode()\n        res_cur = res\n        cur = head\n        num_set = set(nums)\n        \n        while cur:\n            if cur.val not in num_set:\n                res_cur.next = ListNode(cur.val)\n                res_cur = res_cur.next\n            cur = cur.next\n        \n        return res.next\n```\n\n```java []\nclass Solution {\n    public ListNode modifiedList(int[] nums, ListNode head) {\n        ListNode res = new ListNode();\n        ListNode resCur = res;\n        ListNode cur = head;\n        Set<Integer> set = new HashSet<>();\n        for (int num : nums) {\n            set.add(num);\n        }\n        \n        while (cur != null) {\n            if (!set.contains(cur.val)) {\n                resCur.next = new ListNode(cur.val);\n                resCur = resCur.next;\n            }\n            cur = cur.next;\n        }\n        \n        return res.next;\n    }\n}\n```\n\n```javascript []\nvar modifiedList = function (nums, head) {\n    var res = new ListNode();\n    var resCur = res;\n    var cur = head;\n    var set = new Set(nums);\n    while (cur) {\n        if (!set.has(cur.val)) {\n            resCur.next = new ListNode(cur.val);\n            resCur = resCur.next;\n        }\n        cur = cur.next;\n    }\n    return res.next;\n};\n```
['Python', 'C++', 'Java', 'Python3', 'JavaScript']