class Solution {
public:
vector<int> printListReversingly(ListNode* head) {
vector<int> res;
head = reverse(head);
while(head){
res.push_back(head->val);
head = head->next;
}
return res;
}
ListNode* reverse(ListNode *head){
if(head==NULL||head->next==NULL){
return head;
}
ListNode* temp = reverse(head->next);
head->next->next = head;
head->next = NULL;
return temp;
}
};