public ListNode reverseKGroup(ListNode head, int k) {
        ListNode header = new ListNode(0);
        header.next = head;
        
        ListNode[] nodes = new ListNode[k];
        
        int count = 0;
        ListNode pre = header;
        ListNode p = head;
        
        while (p!=null){
	        while(p!=null && count<k){
	        	nodes[count] = p;
	        	p = p.next;    
	        	count++;
	        }
	        
	        if (p!=null || count==k){
	        	ListNode temp = nodes[k-1].next;
	        	for (int i = k-1; i >= 0; i--) {
					pre.next = nodes[i];
					pre = pre.next;
				}
	        	pre.next = temp;
	        }
	        else{
	        	pre.next = nodes[0];
	        }
	        count = 0;
        }
        
        return header.next;
    }