* struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param head ListNode类 
     * @param k int整型 
     * @return ListNode类
     */
    ListNode* reverseKGroup(ListNode* head, int k) {
        // write code here
        if(!head||k<=1)
            return head;
        ListNode *cur,*r,*l;
        cur=head,r=NULL,l=NULL;
        for(int i=1;i<=k;i++){
            if(!cur)
                return head;
            cur=cur->next;
        }
        cur=head;
        for(int i=0;i<k;i++){
            l=cur->next;
            cur->next=r;
            r=cur;
            cur=l;
        }
        head->next=reverseKGroup(cur,k);
        return r;
    }
};