Unexpected error(delete)


  • 0
    L

    Anyone knows why I am getting this error?

    ERROR:
    Runtime Error Message: double free or corruption (top): 0x0000000001f31eb0 ***
    Last executed input:
    [0,1]
    node at index 0 (node.val = 0)

    Is it because something is pointing to current so I cannot delete it?

    MY CODE:

    class Solution {
    public:
    void deleteNode(ListNode* node){
    LIstNode* current = node;
    while(current->next){
    current->val = current->next->val;
    current = current->next;
    }
    delete(current);
    }
    }

    Sorry about the indentation! I did my best.


Log in to reply
 

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