Why isn't it working?


#1

ListNode* Solution::rotateRight(ListNode* A, int B) {

int len=0;
ListNode* head=A;
while (head!=NULL)
{
    len++;
    head=head->next;
}

if (B>len)
    B=B%len;
int loc=len-(B);
if(loc==0 || loc==NULL)
    return A;
int i=0;
ListNode *temp=A;

while(i<loc-1 && temp!=NULL )
{
    temp=temp->next;
    i++;
}
if (temp==NULL)
    return A;
ListNode *knode=temp;
head->next=A;
A=knode->next;
knode->next=NULL;

return A;

}


#2

Found the issue. It’s resolved.

Issue was here:

int len=1;
ListNode* head=A;
while (head->next!=NULL)