/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseKGroup(ListNode* head, int k) {
//if(k == 1||head == NULL)return head;
ListNode* p = head;
ListNode* o = p;
for(int i = 1 ; i < k ; i ++)
{
if(o == NULL)return head;
o = o->next;
}
if(o == NULL)return head;
o->next = reverseKGroup(o->next,k);
o = o->next;
ListNode* q = p->next;
for(int i = 1 ; i < k ; i ++)
{
p -> next = o;
o = p;
p = q;
q = q->next;
}
p -> next = o;
return p;
}
};