public ListNode deleteDuplicates(ListNode head) {
        if(head == null) return null;
        ListNode preHead = new ListNode(0);
        ListNode lastNot = preHead;
        preHead.next = head;
        
        head = head.next;
        while(head != null){
            if(lastNot.next.val != head.val && lastNot.next.next != head){
                lastNot.next = head;
                head = head.next;
            }else if(lastNot.next.val != head.val && lastNot.next.next == head){
                lastNot = lastNot.next;
                head = head.next;
            }else{
                head = head.next;
            }
        }
        if(lastNot.next.next != null){
            lastNot.next = null;
        }
        return preHead.next;
        
    }