题目描述 输入一个链表,从尾到头打印链表每个节点的值。
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
stack<int> stack;
vector<int> vector;
struct ListNode *p=head;
while(p!=NULL){
stack.push(p->val);
p=p->next;
}
while(!
stack.empty()){
vector.push_back(
stack.top());
stack.pop();
}
return vector;
}
};