/**
* 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> ans;
if(head==NULL)return ans;
ListNode* a=head;
while(a)
{
ans.push_back(a->val);
a=a->next;
}
reverse(ans.begin(),ans.end());
return ans;
}
};
剑指offer面试题06. 从尾到头打印链表
最新推荐文章于 2022-08-15 19:55:28 发布