public static ListNode rotateRight(ListNode head, int k) {
int count =1;
int flag =0;
if (head==null){
return head;
}
ListNode temp = head;
while (temp.next!=null){
temp = temp.next;
count++;
}
k=k%count;
flag = count -k;
temp.next = head;
for (int i = flag;i>0;i--){
temp = temp.next;
head = head.next;
}
temp.next=null;
return head;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)