✨🚀 Effortlessly 💯 Dominate 100% with Beginner C++ , Java and Python Solution! 🚀✨
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```C++ []\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(int i : nums) s.insert(i);\n        ListNode* prev = nullptr;\n        ListNode* curr = head;\n        while(curr != nullptr) {\n            if(s.find(curr->val) != s.end()) { // If the current node\'s value is in the set\n                if (prev == nullptr) // If the node to be removed is the head\n                    head = curr->next; // Update the head to the next node\n                else \n                    prev->next = curr->next; // Bypass the current node\n                curr = curr->next; // Move to the next node\n            } else {\n                prev = curr; // Move the prev pointer to the current node\n                curr = curr->next; // Move to the next node\n            }\n        }\n        return head;\n    }\n};\n\n```\n```Java []\npublic class Solution {\n    public ListNode modifiedList(int[] nums, ListNode head) {\n        HashSet<Integer> set = new HashSet<>();\n        for (int num : nums) {\n            set.add(num);\n        }\n        ListNode prev = null;\n        ListNode curr = head;\n        while (curr != null) { // Traverse the list until the end\n            if (set.contains(curr.val)) { // If the current node\'s value is in the set\n                if (prev == null) { // If the node to be removed is the head\n                    head = curr.next; // Update the head to the next node\n                } else {\n                    prev.next = curr.next; // Bypass the current node\n                }\n                curr = curr.next; // Move to the next node\n            } else {\n                prev = curr; // Move the prev pointer to the current node\n                curr = curr.next; // Move to the next node\n            }\n        }\n        return head;\n    }\n}\n```\n```Python []\nclass Solution:\n    def modifiedList(self, nums: List[int], head: Optional[ListNode]) -> Optional[ListNode]:\n        s = set(nums) \n        prev = None \n        curr = head \n        while curr is not None: # Traverse the list until the end\n            if curr.val in s: # If the current node\'s value is in the set\n                if prev is None: # If the node to be removed is the head\n                    head = curr.next # Update the head to the next node\n                else:\n                    prev.next = curr.next # Bypass the current node\n                curr = curr.next # Move to the next node\n            else:\n                prev = curr # Move the prev pointer to the current node\n                curr = curr.next # Move to the next node\n        \n        return head # Return the modified list\n\n```\n\n```
['C++', 'Java', 'Python3']