public ListNode deleteDuplicates(ListNode head) {

    ListNode dummyHead = new ListNode(0);
    dummyHead.next = head;

    ListNode prev = dummyHead;
    ListNode curt = head;

    while (curt != null) {

      ListNode next = curt.next;
      while (next != null && curt.val == next.val) {
        next = next.next;
      }

      if (next == curt.next) {
        prev = curt;
        curt = next;
      } else {
        prev.next = next;
        curt = next;
      }

    }

    return dummyHead.next;
  }