/*
 public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
*/
import java.util.*;
public class Solution {
    public ListNode deleteDuplication(ListNode pHead) {
        Map<Integer,Integer> map=new HashMap<>();
        ListNode cur=pHead; 
        //统计每个链表元素值的次数
        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;
        }
         ListNode res = new ListNode(0);
        //在链表前加一个表头
        res.next=pHead;//连接上
        cur=res;
        //再次遍历 将次数不等于1的给跳过
        while(cur.next!=null){
            if(map.get(cur.next.val)!=1){
                //删除  修改指向
                cur.next=cur.next.next;
            }else{
                
                //向下走
                cur=cur.next;
            }
          
        }
          return res.next;
    }
}