why oj always tell me "runtime erro",while it didn't happen in IDE


  • 0
    W

    ListNode* reverseBetween(ListNode* head, int m, int n) {

        if(m==n)return head;
        ListNode*curp=head;
        ListNode*pre=NULL;
        ListNode*end=NULL;
        for(int i=0;i<=n;i++)
        {
            if(i==m-1)
            pre=curp;
            if(i==n)
            end=curp;
            curp=curp->next;
        }
        ListNode*first=pre->next;
        pre->next=end->next;
        end->next=NULL;
        
        while(first)
        {
            ListNode*tmp=first;
            first=first->next;
            tmp->next=pre->next;
            pre->next=tmp;
        }
        return head;
    }

Log in to reply
 

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