#NEWLINE# def reverseKGroup( self , head , k ) : #NEWLINE# #INDENT# '\n        List\n        O(k*n)\n        :param head: a ListNode\n        :param k: an integer\n        :return: ListNode\n        ' #NEWLINE# dummy = ListNode ( 0 ) #NEWLINE# dummy . next = head #NEWLINE# pre = dummy #NEWLINE# cur_lst = self . generate_lst ( pre . next , k ) #NEWLINE# while ( pre and ( not ( None in cur_lst ) ) ) : #NEWLINE# #INDENT# temp = cur_lst [ ( - 1 ) ] . next #NEWLINE# pre . next = cur_lst [ ( - 1 ) ] #NEWLINE# for i in reversed ( xrange ( k ) ) : #NEWLINE# #INDENT# if ( i == 0 ) : #NEWLINE# #INDENT# cur_lst [ i ] . next = temp #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cur_lst [ i ] . next = cur_lst [ ( i - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# pre = cur_lst [ 0 ] #NEWLINE# cur_lst = self . generate_lst ( pre . next , k ) #NEWLINE# #UNINDENT# return dummy . next