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
.
/** * 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) { if (head = = NULL) return head; listnode* temp = head; &NB Sp int count = 0; while (temp! = NULL) { &NBS P count++; TEMP = temp->next; } & nbsp k = k%count; if (k = = 0) return head; &nbs P listnode* pre = head; listnode* end = head; int I=1;&N Bsp   while (i<k && end->next!=null) { & nbsp End = end->next; i++; } if (i! = k) return head; else &NBSP ; { listnode* temp; while (end->next!=nu LL) { TEMP = pre; &N Bsp PRE = pre->next; end = end->next; } Temp->next = End-> ;next; End->next = head; return pre;& nbsp } }};
Leetcode--rotate List