import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* public ListNode(int val) {
* this.val = val;
* }
* }
*/
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @param k int整型
* @return ListNode类
*/
public ListNode rotateLeft (ListNode head, int k) {
// write code here
ListNode beg = head;//指向头
ListNode end = head;
ListNode node = head;
int c = 0;
while (end.next != null) {
c++;
end = end.next;
}//指向尾
c++;//得到链表长度
for (int i = 0; i < c - k % c; i++) {//根据计算获得与原方向相反方向移动的次数,向反方向移动
//若向原题所说方向移动,尾部结点的前结点一直在变化,不容易获取
//
beg = node.next;
node.next = null;
end.next = node;
end = node;
node = beg;
}
return beg;
}
}