class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
stack<int> arr;
vector<int> result;
while(head!=nullptr)
{
arr.push(head->val);
head = head->next;
}
int len = arr.size();
while(len>0)
{
result.push_back(arr.top());
arr.pop();
len--;
}
return result;
}
};
剑指offer面试题 从尾到头打印链表
最新推荐文章于 2020-11-24 12:10:42 发布