easy to understand c++ solution


  • 0
    K
    ListNode* deleteDuplicates(ListNode* head) {
            if(head==nullptr) return head;
            ListNode *f=head->next,*s=head;
            while(f){
                if(f->val!=s->val){
                    s->next=f;
                    s=s->next;
                }
                f=f->next;
                s->next=nullptr;
            }
            return head;
        }
    

Log in to reply
 

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