做个circle ,看讨论来的
关键是怎么找到从哪里切,最后个循环的条件 len - k%len
public class Solution {
public ListNode rotateRight(ListNode head, int k) {
if(head==null || head.next == null ||k==0) return head;
ListNode n = head;
int len = 1;
while(n.next!=null) {
n = n.next;
len++;
}
n.next = head;
ListNode pre = n;
n = n.next;
for(int i=0; i< len-k%len; i++){
n = n.next;
pre = pre.next;
}
pre.next = null;
return n;
}
}