3m c solution


  • 0
    H

    struct ListNode* deleteDuplicates(struct ListNode* head) {
    struct ListNode* p;
    struct ListNode* q;
    p=head;
    if(!head){
    return head;
    }
    while(p->next){
    q=p->next;
    while(p->val==q->val&&q->next!=NULL){
    q=q->next;
    }
    if(q->next==NULL){
    if(p->val!=q->val){
    p->next=q;
    p=q;
    } else{
    p->next=NULL;
    }
    } else{
    p->next=q;
    p=q;
    }

    }
    return head; 
    

    }


Log in to reply
 

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