I just can't figure it out...


  • 0
    W
    struct ListNode* removeElements(struct ListNode* head, int val) {
    struct ListNode *node = head;
    while(node)
    {
        if(node->val == val)
        {
            node->val = node->next->val;
            node->next = node->next->next;
            free(node->next);
            
        }
        else
            node = node->next;
    }
    return head;
    

    }


  • 0
    D

    e.g:
    listnode:[1]
    value:1
    you can see that the first node existed,but node -> next and node ->next->next are NULL.so you can't use node -> next->val on this situation.
    my english is poor.but i hope you can understand what i said: )


Log in to reply
 

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