Clear solution without leaking MEMORY


  • 0
    K
    void deleteNode(ListNode* node) {
        ListNode* nodeLast;
        while(node->next){
            nodeLast = node;
            node->val = node->next->val;
            node = node->next;
        }
        nodeLast->next = NULL;
        delete node;
    }

Log in to reply
 

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