/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> a;
int num=0;
while(head != nullptr)
{
a.push_back(head->val);
head=head->next;
num+=1;
}
vector<int> b;
int k=num-1;
for(int i=0;i<num;i++)
{
b.push_back(a[k]);
k=k-1;
}
return b;
}
};
(剑指offer)JZ6 从尾到头打印链表(1)
最新推荐文章于 2024-07-22 19:36:52 发布