# 【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) {
int length = 0;
while (p != null) {// 计算表长
length++;
if (p.next == null) {
rear = p;// rear指向表尾
}
p = p.next;
}
if (head == null || length == 0) {
}
if (k > length) {
k = k % length;
}
if (k == 0 || k == length) {
}

int rotateIndex = length - k;
while (--rotateIndex > 0) {
p = p.next;
} // 此时p指向倒数k+1一个位置

p.next = null;
}


#### LeetCode 61 — Rotate List（C++ Java Python）

2014-02-24 22:11:31

#### LeetCode -- Rotate List

2015-11-07 18:25:03

#### (Java)LeetCode-61. Rotate List

2016-10-06 17:52:28

#### leetcode Rotate list （链表旋转）的python实现

2017-05-12 18:35:04

#### 【LeetCode-面试算法经典-Java实现】【061-Rotate List（旋转单链表）】

2015-08-01 07:13:45

#### 【LeetCode with Python】 Rotate List

2014-08-29 18:34:04

#### [leetcode-61]Rotate List(c)

2015-08-04 09:04:28

#### LeetCode - 67. Rotate Matrix

2016-06-28 11:20:36

#### [Leetcode] 796. Rotate String 解题报告

2018-03-30 20:08:14

#### LeetCode（48）Rotate Image

2015-08-31 20:49:30