public static ListNode deleteDuplicates(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode curr = new ListNode(-1);
        curr.next = head;
        head = curr;

        while(curr.next != null){
            ListNode end = curr.next;
            while(end.next != null && (end.val == end.next.val)){
                end = end.next;
            }
            if(end == curr.next){
                curr = curr.next;
            }else{
                curr.next = end.next;
            }
        }
        return head.next;
    }