So easy with c++!


  • -1
    Z
    void deleteNode(ListNode* node) 
    {
        if(node->next)
        {
            node->val=node->next->val;
            node->next=node->next->next;
        }
        else
            node=NULL;
    }

  • 0
    J

    memory leak?


  • 0
    S

    @Johnson04 how about this?

    node->val = node->next->val;
    struct ListNode* temp = node->next;
    node->next = node->next->next;
    
    free(temp);
    

    Also I think there is no need to check
    if(node->next)
    as the question says "delete a node (except the tail)"


Log in to reply
 

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