public ListNode reverseKGroup(ListNode head, int k) {
        if (head == null || k <= 1) {
            return head;
        }
        
        int length = 0;
        ListNode it = head;
        while (it != null) {
            length++;
            it = it.next;
        }
        
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode grp_prehead = dummy;
        for (int i = 0; i < (int)(length / k); i++) {
            ListNode grp_tail = grp_prehead.next;
            for (int j = 0; j < k - 1; j++) {
                ListNode move_node = grp_tail.next;
                grp_tail.next = move_node.next;
                move_node.next = grp_prehead.next;
                grp_prehead.next = move_node;
            }
            grp_prehead = grp_tail;
        }
        return dummy.next;
    }