/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* reverseKGroup(ListNode* head, int k) {
stack<int> my_stack;
vector<int> v_nums;
ListNode* tmp = head;
int num = 0;
while(tmp != nullptr && num < k)
{
num++;
v_nums.push_back(tmp->val);
my_stack.push(tmp->val);
if(num == k)
{
while(num--) v_nums.pop_back();
num = k;
while(num--)
{
v_nums.push_back(my_stack.top());
my_stack.pop();
}
cout<<num<<' ';
num = 0;
}
tmp = tmp->next;
}
tmp = head;
int i=0;
while(tmp != nullptr)
{
tmp->val = v_nums[i];
tmp = tmp->next;
i++;
}
return head;
}
};