import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* }
*/
public class Solution {
/**
*
* @param head ListNode类
* @return ListNode类
*/
public ListNode deleteDuplicates (ListNode head) {
// write code here
ArrayList<Integer>res=new ArrayList<>();
Map<Integer,Integer> map=new HashMap<>();
ListNode cur=head;
while(cur!=null){
if(map.containsKey(cur.val)){
map.put(cur.val,(int)map.get(cur.val)+1);
}else{
map.put(cur.val,1);
}
cur=cur.next;
}
for(Object i:map.keySet()){
if((int)map.get(i)==1){
res.add((int)i);
}
}
int i=0;
ListNode first=new ListNode(0);
ListNode tt=first;
Collections.sort(res);
while(i<res.size()){
ListNode temp=new ListNode((int)res.get(i));
tt.next=temp;
tt=temp;
i++;
}
return first.next;
}
}