JAVA | 100% Beats ✅
\n# Code\njava []\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\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        int max = 0;\n        for (int i : nums) \n            max = Math.max(max, i);\n\n        boolean [] visited = new boolean[max + 1];\n\n        for (int i : nums) visited[i] = true;\n\n        ListNode dummy = new ListNode(-1);\n        dummy.next = head;\n        ListNode curr = dummy;\n\n        while (head != null) {\n            if(head.val <= max && visited[head.val])\n                dummy.next = head.next;\n            else\n                dummy = head;\n            head = head.next;\n        }\n\n        return curr.next;\n    }\n}\n```
['Java']