/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
#include <cstddef>
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
ListNode* next=nullptr;
ListNode* front=nullptr;
while(head)
{
next=head->next;
head->next=front;
front=head;
head=next;
}
vector<int> a;
while(front)
{
a.push_back(front->val);
front=front->next;
}
return a;
}
};



京公网安备 11010502036488号