Deleting Nodes Using Link Updation And Fast Look Ups Using Set | Java | C++ | [Video Solution]
Intuition, approach, and complexity discussed in video solution in detail.\nhttps://youtu.be/32-3yHQy4ek\n\n# Code\njava []\nclass Solution {\n    public ListNo
# Intuition, approach, and complexity discussed in video solution in detail.\nhttps://youtu.be/32-3yHQy4ek\n\n# Code\n```java []\nclass Solution {\n    public ListNode modifiedList(int[] nums, ListNode head) {\n        Set<Integer> toBeDel = new HashSet<>();\n        for(var num : nums)toBeDel.add(num);\n        ListNode dummyHead = new ListNode();\n        dummyHead.next = head;\n        ListNode curr = dummyHead, prev = dummyHead;\n        while(curr != null){\n            ListNode nextNode = curr.next;\n            if(toBeDel.contains(curr.val)){\n                prev.next = nextNode;\n            }else{\n                prev = curr;\n            }\n            curr = nextNode;\n        }\n        return dummyHead.next;\n    }\n}\n```\n``` cpp []\nclass Solution {\npublic:\n    ListNode* modifiedList(vector<int>& nums, ListNode* head) {\n        unordered_set<int> toBeDel;\n        for(auto & num : nums)toBeDel.insert(num);\n        ListNode *dummyHead = new ListNode();\n        dummyHead->next = head;\n        ListNode *curr = dummyHead, *prev = dummyHead;\n        while(curr != NULL){\n            ListNode *nextNode = curr->next;\n            if(toBeDel.count(curr->val) != 0){\n                prev->next = nextNode;\n            }else{\n                prev = curr;\n            }\n            curr = nextNode;\n        }\n        return dummyHead->next;\n    }\n};\n```
['Array', 'Hash Table', 'Linked List', 'C++', 'Java']