Time Limit Exceeded.How can I improve?


#1

ListNode*curr,*next,*prev,*last;
int c=0;
prev=NULL;
curr=A;
if(A!=NULL && A->next!=NULL)
{
while(c<B)
{
prev=curr;
curr=curr->next;
}
c=0;
last=A;
while(c<C)
{
last=last->next;
}

while(curr!=last)
{
    next=curr->next;
    curr->next=prev;
    prev=curr;
    curr=next;
}
if(B==1)
return prev;
else return A;
}
else
return A; here.