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

        Set<Integer> set = new HashSet<Integer>();
        set.add( head.val );
        ListNode p = head.next;
        ListNode prev = head;
        while( p != null ) {
            if( set.contains( p.val ) ) {
                prev.next = p.next;
                p = p.next;
            } else {
                set.add( p.val );
                p = p.next;
                prev = prev.next;
            }
        }
        return head;
    }