C++ simple solution


  • -3
    C

    ListNode* removeElements(ListNode* head, int val) {
    ListNode *pre, *prehead;
    pre->next = head;
    prehead=pre;
    while(head){
    if (head->val==val){
    head=head->next;
    pre->next=head;
    }else{
    pre=head;
    head=head->next;
    }
    }
    return prehead->next;
    }


Log in to reply
 

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