4 ms, C solution


  • 0
    A

    Plz chk below to get my C answer:

    struct ListNode* chk_node = (head == NULL) ? 0: head;
    struct ListNode* last_node = chk_node;
    while(chk_node != NULL){
        if (chk_node->val == val){
            if (chk_node == head)
                head = (chk_node->next == NULL) ? 0:chk_node->next;
            else
                last_node->next = (chk_node->next == NULL) ? 0:chk_node->next;
        } else {
            last_node = chk_node;
        }
        chk_node = (chk_node->next == NULL) ? 0:chk_node->next;
    }
    return head;

Log in to reply
 

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