/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
stack<int> S;
for(ListNode* p = head; p; p = p->next) {
S.push(p->val);
}
vector<int> V;
while(!S.empty()) {
V.push_back(S.top());
S.pop();
}
return V;
}
};
【剑指offer】JZ3 从尾到头打印链表(C++)
最新推荐文章于 2021-03-24 23:35:59 发布