/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
vector<int> res;
while(head)
{
res.push_back(head->val);
head = head->next;
}
return vector<int>(res.rbegin(),res.rend());
}
};
剑指 Offer 06. 从尾到头打印链表
最新推荐文章于 2023-06-22 17:10:40 发布