Why runtime error ? Is there something wrong ?


  • 0
    L

    class Solution {

    public:

    ListNode* oddEvenList(ListNode* head) {
        ListNode *a, *b, *cur;
        cur=head;
        b=cur->next;
        a=b;
        while(cur->next!=NULL&&cur->next->next!=NULL)
        {
            cur->next=cur->next->next;
            a->next=cur->next->next;
            cur=cur->next;
            a=a->next;
        }
        cur->next=b;
        return head;
    }
    

    };


  • 0
    C

    cur=head;
    b=cur->next;

    cur may be NULL.


Log in to reply
 

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