What is wrong with my code


  • 0
    A
    ListNode *deleteDuplicates(ListNode *head) {
        ListNode*temp=head,*prev,*save1,*save2;
        int flag=1;
        prev->val=-1;
            prev->next=temp;
        while(temp!=NULL && temp->next!=NULL)
        {
            if(temp->next->val==temp->val)
            {
                flag=0;
             save1=temp->next;
             save2=temp;`prev->next=temp->next->next;
                
            }
            prev=temp;
            temp=temp->next;
            if(!flag)
            {delete save1;`delete save2;
                
            }
            flag=1;
            
        }
        return head;`

Log in to reply
 

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