class Solution {
public ListNode rotateRight(ListNode head, int k) {
ListNode pre=head;
ListNode first=head;
ListNode second=head;
ListNode len=pre;
int length=1;
if(head==null)return pre;
while(len.next!=null){
length++;
len=len.next;
}
k=k%length;
if(k==0||head==null)return pre;
for(int i=0;i<k;i++){
first=first.next;
}
while(first.next!=null){
first=first.next;
second=second.next;
}
pre=second.next;
first.next=head;
second.next=null;
return pre;
}
}