トピック:
コード:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
stack<int> s;
vector<int> ans;
while(head!=NULL)
{
s.push(head->val);
head=head->next;
}
while(s.size())
{
ans.push_back(s.top());
s.pop();
}
return ans;
}
};