C++ 6 lines 9ms solution


  • 0
     ListNode* deleteDuplicates(ListNode* head) {
            if(head==NULL) return NULL;
            ListNode* cur=head,*next=head->next;
            while(next!=NULL)
                if(cur->val==next->val) cur->next=next->next,next=cur->next;
                else cur=cur->next,next=cur->next;
            return head;
        }
    

Log in to reply
 

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