# LeetCode进阶之路（Rotate List）

Given a list, rotate the list to the right by k places, where k is non-negative.

For example:
Given 1->2->3->4->5->NULL and k = 2,
return 4->5->1->2->3->NULL.

public ListNode rotateRight(ListNode head, int k) {

ListNode result = new ListNode(-1);
ListNode first = result;
ListNode third = result;
return result.next;
}
}
int len = 1;
while(result.next != null) {
len++;
result = result.next;
}
int i = 0;
while(i < len-k) {
i++;
first = first.next;
}
third.next = first;
int j = 1;
while(j < len-1-k) {
second = second.next;
j++;
}
second.next = null;

ListNode flag = third;
while(flag.next != null) {
flag = flag.next;
}

return third.next;

}

public ListNode rotateRight(ListNode head, int n) {
int len = 0;

while(countlen!=null){
len++;
countlen = countlen.next;
}

n = n%len;
if(n==0)

for(int i = 0; i < n; i++)
fast = fast.next;

while(fast.next!=null){
slow = slow.next;
fast = fast.next;
}

slow.next = null;

}

public ListNode rotateRight(ListNode head, int n) {

if (head == null || n == 0)
while (p.next != null) {
len++;
p = p.next;
}
p.next = head; //form a loop
n = n % len;
for (int i = 0; i < len - n; i++) {
p = p.next;
} //now p points to the prev of the new head
}