代码
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> res;
while (head){
res.push_back(head->val);
head = head->next;
}
std::reverse(res.begin(),res.end());
return res;
}
};
思路
遍历链表,放入vector,反转vector。