public ListNode deleteDuplicates(ListNode head) {
        if(head == null){
            return null;
        }
        ListNode superHead = new ListNode(0);
        superHead.next = head;
        ListNode previous = superHead;
        ListNode check = head;
        boolean dup = false;
        while(check.next !=null){
            if(check.val == check.next.val){
                dup = true;
                check = check.next;
            }
            else {
                if (dup){
                    previous.next = check.next;
                    check = previous.next;
                    dup = false;
                }
                else {
                    previous = check;
                    check = check.next;
                }
            }
        }
        if(dup){
            previous.next = null;
        }
        return superHead.next;
    }