😔😔😔

import java.util.*;

public class Solution {
    public ListNode deleteDuplicates (ListNode head) {
        if(head==null||head.next==null)
            return head;

        ListNode newHead = new ListNode(0);
        ListNode pre = newHead;

        HashMap<Integer,Integer> hm = new LinkedHashMap<>();

        while(head!=null)
        {
            if(hm.containsKey(head.val))
                hm.put(head.val,hm.get(head.val)+1);
            else
                hm.put(head.val,1);
            head = head.next;
        }

        for(Integer keys : hm.keySet()){
            if(hm.get(keys)==1){
                pre.next = new ListNode(keys);
                pre = pre.next;
            }
        }

        pre = null;
        return newHead.next;
    }
}