代码
class Solution {
public:
vector<int> reversePrint(ListNode* head) {
vector<int>res;
while(head){
res.push_back(head->val);
head=head->next;
}
reverse(res.begin(),res.end());
return res;
}
};
思路
遍历链表在数组中存入值,最后反转数组
遍历链表在数组中存入值,最后反转数组
遍历链表在数组中存入值,最后反转数组