Simple c solution.


  • 1
    Z
    struct ListNode* removeElements(struct ListNode* head, int val) {
        struct ListNode **prev, *curr;
        
        prev = &head;
        curr = head;
        
        while (curr) {
            if (curr->val == val)
                *prev = curr->next;
            else 
                prev = &(curr->next);
            curr = curr->next;
        }
        return head;
    }
    

    Use pointer's pointer.


Log in to reply
 

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