BEATS 98.49% 💯✅ || BEST AND EASY APPROACH 🔥🚀|| JAVA
Intuition\n Describe your first thoughts on how to solve this problem. \nThe function removes nodes from a linked list if their values are present in a given ar
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe function removes nodes from a linked list if their values are present in a given array. It first marks the values to be removed using a boolean array for quick lookup. Then, as it traverses the linked list, it adjusts pointers to exclude the nodes with marked values, effectively removing them from the list.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.  Array Marking: We create a boolean array arr of size 100001, assuming the maximum possible value for nums is 100000. This array is used to mark the elements that need to be removed.\n\n2. Traversing the Linked List: We iterate through the linked list:\n\n- For each node, check if its value exists in the arr array (i.e., if it needs to be removed).\n- If it does, we adjust the pointers to remove the node from the list.\n- If it\'s the head node, we update the head of the list.\n3. Edge Case: If the head node needs to be removed, special handling is required to update the head pointer correctly.\n\n# Complexity\n- Time complexity: O(n+m) \nn - number of elements in the array\nm - number of nodes in the linked list\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```java []\n/**\nclass Solution {\n    public ListNode modifiedList(int[] nums, ListNode head) {\n        boolean[] arr= new boolean[(int)1e5+1];\n        for(int num:nums){\n            arr[num] = true;\n        }\n\n        ListNode prev = null;\n        ListNode curr = head;\n        while(curr!=null){\n            if(arr[curr.val]==true){\n                if(prev==null){ //delition at head vala\n                    head= curr.next;\n                    curr.next = null;\n                    curr= head;\n                }else{\n                    prev.next = curr.next;\n                    curr.next = null;\n                    curr = prev.next;\n                }\n            }else{\n                prev= curr;\n                curr = curr.next;\n            }\n        }\n        return head;\n    }\n}\n```
['Java']