My simple c++ solution


  • 0
    K
    class Solution {
    public:
    ListNode* removeElements(ListNode* head, int val) {
        if(!head)return NULL;
        ListNode * temp=head;
        while(temp)
        {
            if(temp==head && temp->val==val){
                temp=temp->next;
                head=temp;
            }
            else if(temp->next && temp->next->val==val)temp->next=temp->next->next;
            else temp=temp->next;
        }
        return head;
    }
    

    };


Log in to reply
 

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