/*
 * function ListNode(x){
 *   this.val = x;
 *   this.next = null;
 * }
 */

/**
  * 
  * @param head ListNode类 
  * @param k int整型 
  * @return ListNode类
  */
function reverseKGroup( head ,  k ) {
    // write code here
        let pre = null
    let current = head
    let node = head
    for(let i = 0; i<k;i++){
        if(node === null){
            return head;
        }
        node = node.next;
    }
    for(let j = 0;j<k;j++){
        let temp = current.next;//这里用temp保存一下
        current.next = pre;
        pre = current;
        current = temp;
    }
    head.next = reverseKGroup(current,k)
    return pre
}
module.exports = {
    reverseKGroup : reverseKGroup
};