/**
* 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> ve;//上面链表不是vector,用不了逆序方法,可创建一个副本vector容器,用反向迭代的方式输出
while(head){
ve.push_back(head->val);
head=head->next;
}
return vector<int>(ve.rbegin(),ve.rend());//反向迭代
}
};