Middle-题目107：61. 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.

/**
* struct ListNode {
*     int val;
*     struct ListNode *next;
* };
*/
struct ListNode* rotateRight(struct ListNode* head, int k) {
struct ListNode* end;
int count=1;
for(end = head; end->next; end = end->next)
count++;
for(int i=1;i<count-k%count;i++) {
p1=p1->next;
p2=p2->next;
}
p1->next = NULL;
return p2;
}

4ms,beats 6.02%，众数4ms,93.98%
cmershen的碎碎念：

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

2014-02-24 22:11:31

(Java)LeetCode-61. Rotate List

2016-10-06 17:52:28

LeetCode --- 61. Rotate List

2015-03-15 23:33:07

[leetcode-61]Rotate List(c)

2015-08-04 09:04:28

Leetcode——61. Rotate List

2017-01-26 00:55:41

LeetCode | 61. Rotate List

2017-07-07 10:58:09

快慢指针之-61. Rotate List

2017-10-27 10:04:00

61. Rotate List LeetCode

2016-03-17 22:00:07

61. Rotate List(unsolved)

2017-03-02 01:10:46

[leetcode]61. Rotate List

2017-05-18 10:46:28