Simple c solution.

  • 1
    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;
                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.