输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。
 
示例 1:
输入:head = [1,3,2]
输出:[2,3,1]
 
限制:
0 <= 链表长度 <= 10000
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof
 
vector的插入字符是push_back,结点的数据是用->,reverse是algorithm中的算法可以直接反转
 1 class Solution {
 2 public:
 3     vector<int> res;
 4     vector<int> reversePrint(ListNode* head) {
 5         while(head)
 6         {
 7             res.push_back(head->val);
 8             head=head->next;
 9         }
10         reverse(res.begin(),res.end());
11         return res;
12     }
13 };