/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *rotateRight(ListNode *head, int k) {
ListNode *p=head;
int num = 1;
if(!p)
return NULL;
while(p->next)
{
p = p->next;
num++;
}
p->next = head;
int step = num-k%num;
for(int i=0;inext;
}
head = p->next;
p->next = NULL;
return head;
}
};