My beautiful java solution


  • 0
        public ListNode deleteDuplicates(ListNode head) {
            if(head == null) return null;
            ListNode cur = head;
            ListNode pre = cur.next;
            while(cur != null){
                while(pre!= null && pre.val == cur.val){
                    pre = pre.next;
                }
                cur.next = pre;
                cur = pre;
            }
            return head;
        }
    
    ``

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.