DELETE IN DISGUISE ✅✅69_BEATS_100%✅✅🔥Easy Solution🔥With Explanation🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nwe need to drop off all the nodes we dont want ie which are already in the nums array w
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe need to drop off all the nodes we dont want ie which are already in the nums array we can use 2 pointers to do this lets see\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nfirst of all we will hash set the nums array for O(1) look up\nthen we will attach an empty node to our head and an anchor pointer to this empty node\n\nthen we will start travelling \nwhile there is a node next to our moving pointer,\nwe will check if this pointer is in the set or not \nif it is we have to drop it we will assign the next of our pointer to the next.next to skip this node \nif the node is not in the set we will simply move forward with the next node \n\nfinally since our anchor is pointing to an empty node \nwe will retrn anchor .next \nthats it \n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\nvar modifiedList = function(nums, head) {\n    const set = new Set(nums);\n    let cur = new ListNode(null, head);\n    let newHead = cur;\n\n    while(cur.next) {\n        if(set.has(cur.next.val)) {\n            cur.next = cur.next.next;\n        } else {\n            cur = cur.next;\n        }\n    }\n\n    return newHead.next;\n};\n```\n```python []\nclass ListNode:\n    def __init__(self, x, next=None):\n        self.val = x\n        self.next = next\n\ndef modified_list(nums, head):\n    num_set = set(nums)\n    dummy = ListNode(None, head)\n    current = dummy\n\n    while current.next:\n        if current.next.val in num_set:\n            current.next = current.next.next\n        else:\n            current = current.next\n\n    return dummy.next\n\n```\n```ruby []\nimport java.util.HashSet;\nimport java.util.Set;\n\nclass ListNode {\n    int val;\n    ListNode next;\n    ListNode(int x) {\n        val = x;\n        next = null;\n    }\n    ListNode(int x, ListNode next) {\n        val = x;\n        this.next = next;\n    }\n}\n\npublic class Solution {\n    public ListNode modifiedList(int[] nums, ListNode head) {\n        Set<Integer> set = new HashSet<>();\n        for (int num : nums) {\n            set.add(num);\n        }\n\n        ListNode dummy = new ListNode(-1, head);\n        ListNode current = dummy;\n\n        while (current.next != null) {\n            if (set.contains(current.next.val)) {\n                current.next = current.next.next;\n            } else {\n                current = current.next;\n            }\n        }\n\n        return dummy.next;\n    }\n}\n\n```\n```c []\n#include <stdlib.h>\n#include <stdbool.h>\n\ntypedef struct ListNode {\n    int val;\n    struct ListNode *next;\n} ListNode;\n\ntypedef struct HashSet {\n    bool *data;\n    int size;\n} HashSet;\n\nHashSet* createHashSet(int max_size) {\n    HashSet *set = (HashSet *)malloc(sizeof(HashSet));\n    set->data = (bool *)calloc(max_size, sizeof(bool));\n    set->size = max_size;\n    return set;\n}\n\nvoid addToHashSet(HashSet *set, int num) {\n    if (num >= 0 && num < set->size) {\n        set->data[num] = true;\n    }\n}\n\nbool containsHashSet(HashSet *set, int num) {\n    return num >= 0 && num < set->size && set->data[num];\n}\n\nvoid freeHashSet(HashSet *set) {\n    free(set->data);\n    free(set);\n}\n\nListNode* modifiedList(int* nums, int numsSize, ListNode* head) {\n    HashSet *set = createHashSet(100000);  // Assume a large enough size\n    for (int i = 0; i < numsSize; i++) {\n        addToHashSet(set, nums[i]);\n    }\n\n    ListNode dummy = {0, head};\n    ListNode *current = &dummy;\n\n    while (current->next != NULL) {\n        if (containsHashSet(set, current->next->val)) {\n            ListNode *temp = current->next;\n            current->next = temp->next;\n            free(temp);\n        } else {\n            current = current->next;\n        }\n    }\n\n    freeHashSet(set);\n    return dummy.next;\n}\n```
['Array', 'Hash Table', 'Linked List', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#']