public ListNode deleteDuplicates_UGLY(ListNode head) {

    if (head == null) {
      return null;
    }

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

    ListNode prev = dummyHead;
    ListNode curt = head;
    ListNode next = head.next;

    boolean flag = false;
    while (curt != null) {

      // every time use next, need to add a null pointer checker
      // bad bad bad
      if (next != null && curt.val == next.val) {
        prev.next = curt.next;
        curt = next;
        next = next.next;

        flag = true;
      } else {
        if (flag) {
          prev.next = curt.next;
          curt = next;
          if (next != null) {
            next = next.next;
          }
        } else {
          prev = prev.next;
          curt = curt.next;
          if (next != null) {
            next = next.next;
          }
        }
        flag = false;
      }


    }
    return dummyHead.next;
  }