Java Solution using Set
Intuition\n1. Add all the items of nums into set.\n2. now iterate over the linked list.\n3. if the current node\'s value is present in the set then skip that no
# Intuition\n1. Add all the items of nums into set.\n2. now iterate over the linked list.\n3. if the current node\'s value is present in the set then skip that node else adjust the prev pointer as used in the code and move the pointer on next node.\n\n# Complexity\n- Time complexity: size of linked list(n)\n\n- Space complexity: length of nums array(m)\n\n# Code\n```java []\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode modifiedList(int[] nums, ListNode head) {\n        ListNode dummy = new ListNode(0);\n        dummy.next = head;\n        ListNode prev = dummy;\n        ListNode temp = head;\n        Set<Integer> set = new HashSet<>();\n        for(int i=0; i<nums.length; i++){\n            set.add(nums[i]);\n        }\n        while(temp!=null){\n            if(!set.contains(temp.val)){\n                prev.next = temp;\n                prev = temp;\n            }\n            temp = temp.next;\n        }\n        if(prev.next!=null)prev.next = null;\n        return dummy.next;\n    }\n}\n```
['Java']