import java.util.*; public class Solution { public ListNode deleteDuplicates (ListNode head) { ListNode node=head; HashMap<Integer,Integer> map=new HashMap<>(); while(head!=null){ if(map.containsKey(head.val)){ map.put(head.val,map.get(head.val)+1); }else{ map.put(head.val,1); } head=head.next; } ListNode list=new ListNode(-1); list.next=node; ListNode cur=list; while(node!=null){ if(map.get(node.val)>1){ list.next=list.next.next; }else{ list=list.next; } node=node.next; } return cur.next; } }