/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* @param head ListNode类
* @param k int整型
* @return ListNode类
*/
//每k个,可以使用递归
function reverseKGroup( head , k ) {
// write code here
let curr=head
let prev=null
let node=head
for(let i=0;i<k;i++){
if(node==null){
return head
}
node=node.next
}
for(let i=0;i<k;i++){
let next=curr.next
curr.next=prev
prev=curr
curr=next
}
head.next=reverseKGroup(curr,k)
return prev
}
module.exports = {
reverseKGroup : reverseKGroup
};