# 旋转链表
给你一个链表的头节点 head
,旋转链表,将链表每个节点向右移动 k
个位置。
示例 1:

输入:head = [1,2,3,4,5], k = 2
输出:[4,5,1,2,3]
示例 2:

输入:head = [0,1,2], k = 4
输出:[2,0,1]
提示:
- 链表中节点的数目在范围
[0, 500]
内 -100 <= Node.val <= 100
0 <= k <= 2 * 109
## template
```java
public class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
}
}
class Solution {
public ListNode rotateRight(ListNode head, int k) {
if (head == null || k == 0) {
return head;
}
ListNode cursor = head;
ListNode tail = null;
int length = 1;
while (cursor.next != null) {
cursor = cursor.next;
length++;
}
int loop = length - (k % length);
tail = cursor;
cursor.next = head;
cursor = head;
for (int i = 0; i < loop; i++) {
cursor = cursor.next;
tail = tail.next;
}
tail.next = null;
return cursor;
}
}
```
## 答案
```java
```
## 选项
### A
```java
```
### B
```java
```
### C
```java
```