解题思路:
使用栈(先进后出的想法)
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> ArrayList;
stack<int> ArrayStack;
ListNode* pNode=head;
while(pNode!=nullptr)
{
ArrayStack.push(pNode->val);
pNode=pNode->next;
}
while(!ArrayStack.empty()){
ArrayList.push_back(ArrayStack.top());
ArrayStack.pop();
}
return ArrayList;
}
};