my c solution


  • 0
    L

    struct ListNode* removeElements(struct ListNode* head, int val) {
    struct ListNode tmpNode = {0, head};
    struct ListNode *pre = &tmpNode;
    struct ListNode *current = head;
    while (current != NULL) {
    if (current->val == val) {
    pre->next = current->next;
    } else {
    pre = current;
    }
    current = current->next;
    }
    return tmpNode.next;
    }


Log in to reply
 

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