Java Clean Solution | Linear Traversal
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
# 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```\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        Set<Integer> set = new HashSet<>();\n        for(int num:nums){\n            set.add(num);\n        }\n        \n        ListNode res = new ListNode(0);\n        res.next = head;\n        \n        ListNode curr = res;\n        while(curr.next != null){\n            if(set.contains(curr.next.val)){\n                curr.next = curr.next.next;\n            }else{\n                curr = curr.next;\n            }\n        }\n        return res.next;\n    }\n}\n```
['Array', 'Hash Table', 'Linked List', 'Doubly-Linked List', 'Java']