class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
stack<int> stk;
ListNode *p = head;
while(p != nullptr)
{
stk.push(p->val);
p = p->next;
}
vector<int> vec;
while(!stk.empty())
{
vec.push_back(stk.top());
stk.pop();
}
return vec;
}
};