Simple iterative method


#1

ListNode* Solution::rotateRight(ListNode* A, int B) {
if(A==NULL || A->next==NULL)
return A;
ListNode* temp=A;
int count=0;
while(temp->next!=NULL){
temp=temp->next;
count++;
}
count++;
temp->next=A;
temp=A;
B=B%count;
int x=count-B;
for(int i=0;i<x-1;i++)
temp=temp->next;
A=temp->next;
temp->next=NULL;
return A;
}


#2

This really helped! Thanks!