blob: 8cbbe17dfc56ba18f39aba780685ebf8a02e91a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include <stdio.h>
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode {
int val;
struct ListNode *next;
};
struct ListNode* rotateRight(struct ListNode* head, int k)
{
int i;
int length = 1;
struct ListNode* p = head;
if(p == NULL) return head;
for(; p->next != NULL; p = p->next)
length++;
p->next = head;
for(i = 0; i < length - k % length; i++)
p = p->next;
head = p->next;
p->next = NULL;
return head;
}
int main()
{
}
|