从尾到头打印链表(vector反向 迭代器)
https://www.acwing.com/problem/content/18/
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
vector<int> printListReversingly(ListNode* head) {
vector<int>res;
while(head!=NULL)
{
res.push_back(head->val);
head = head->next;
}
return vector<int>(res.rbegin(),res.rend());
}
};