/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
将所有数据装入栈中即可,也可以用三指针法
class Solution {
public:
vector printListFromTailToHead(ListNode* head) {
stack s;
vector v;
ListNode* cur = head;
while(cur)
{
s.push(cur->val);
cur=cur->next;
}
while(!s.empty())
{
v.push_back(s.top());
s.pop();
}
return v;
}
};