class Solution {
public ListNode rotateRight(ListNode head, int k) {
if(head == null){
return null;
}
ListNode cur = head;
int n = 1;
while(cur.next != null){
cur = cur.next;
n++;
}
cur.next = head;
ListNode helper = head;
int i = 0;
while(i < n - k%n -1){
helper = helper.next;
i++;
}
head = helper.next;
helper.next = null;
return head;
}
}