public ListNode deleteDuplicates(ListNode head) {
        if( head == null || head.next == null ) return head;
        Map<Integer, Integer> freqMap = new HashMap<Integer, Integer>();

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

        p = head;
        ListNode prev = null;
        while( p != null ) {
            if( freqMap.get(p.val) > 1 ) {
                if( prev != null ) {
                    prev.next = p.next;
                } else {
                    head = p.next;
                }
                p = p.next;
            } else {
                prev = p;
                p = p.next;
            }
        }
        return head;
    }