思路:直接遍历 然后存储,简单。
/**
* 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> a;
while(head!=NULL){
a.push((*head).val);
head=(*head).next;
}
vector<int> as;
while(a.size()){
as.push_back(a.top());
a.pop();
}
return as;
}
};