public ListNode deleteDuplicates(ListNode head) {
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        head = dummy;
        while (head.next != null) {
            ListNode p = head.next;
            while (p != null && p.val == head.next.val) {
                p = p.next;
            }
            if (p == head.next.next) { // ignore non-dups
                head = head.next;
            } else { // remove dups
                head.next = p;
            }
        }
        return dummy.next;
    }