Can someone help me to figure out my problem on runtime error


  • 0
    B

    My code is right on most input, however, when [4,77,57,79,24,47,21,42,38,54,26,28,30,85,32,40,62,28,89,37,24,3,51,72,59,49,7,60,44,7,27,48,37,37,27,13,36,49,55,26,55,33,55,85,19,39,25,33,68,14,70,44,70,73,68,29,22,27,89,66,35,69,67,24,58,94,37,46] there's a runtime error.

    class Solution {
    public:

        ListNode* swapPairs(ListNode* head) {
        ListNode *path,*res;
    
        if (!head||!head->next)
        return head;
        res->next=head->next;
        path->next=head;
        while(path&&path->next&&path->next->next)
        {
           ListNode *temp,*temp2;
           temp=path->next->next;
           temp2=path->next;
           temp2->next=temp->next;
           temp->next=temp2;
           path->next=temp;
           path=temp2;
        }
    
        return res->next;
    }
    

    };

    This is my code.

    Thanks!


Log in to reply
 

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