# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

#
# 
# @param head ListNode类 
# @param k int整型 
# @return ListNode类
#
class Solution:
    def reverseKGroup(self , head , k ):
        # write code here
        if not head: return head
        
        cur = head
        for i in range(k):
            if not cur: return head 
            cur = cur.next
            
        tem = self.reverse_list(head, cur)
        head.next = self.reverseKGroup(cur, k)
        return tem
    
    def reverse_list(self, head, end):
        if head==end: return head
        cur = head
        c1 = None
        while cur!= end:
            tem = cur.next
            cur.next = c1 
            c1 = cur
            cur = tem
        return c1