# 旋转链表

<p>给你一个链表的头节点 <code>head</code> ，旋转链表，将链表每个节点向右移动 <code>k</code><em> </em>个位置。</p><p> </p><p><strong>示例 1：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/c0d8ae472058ab78d44488d3d18b7d34.jpeg" style="width: 600px; height: 254px;" /><pre><strong>输入：</strong>head = [1,2,3,4,5], k = 2<strong><br />输出：</strong>[4,5,1,2,3]</pre><p><strong>示例 2：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/b36376b20ad1074341ffc8bca9a32eca.jpeg" style="width: 472px; height: 542px;" /><pre><strong>输入：</strong>head = [0,1,2], k = 4<strong><br />输出：</strong>[2,0,1]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li>链表中节点的数目在范围 <code>[0, 500]</code> 内</li>	<li><code>-100 <= Node.val <= 100</code></li>	<li><code>0 <= k <= 2 * 10<sup>9</sup></code></li></ul>

## 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

```