Other approach for this question


#1

Comment body goes here.int find_size(ListNode* root){
ListNode* temp=root;
int cnt=0;
while(temp!=NULL){
cnt++;
temp=temp->next;
}
return cnt;

}
ListNode* Solution::rotateRight(ListNode* root, int k) {
int n=find_size(root);
k=k%n;
if(k==0 || k==n){
return root;
}
int times=n-k-1;
ListNode* current=root;
while(times–){
current=current->next;
}
ListNode* temp=current->next;
while(temp->next !=NULL){
temp=temp->next;
}
temp->next=root;
ListNode* ans=current->next;
current->next=NULL;
return ans;

}