class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
if(head == nullptr) {
return {};
}
vector<int> res;
helper(res, head);
return res;
}
void helper(vector<int>& res, ListNode* head) {
if(head->next == nullptr) {
res.push_back(head->val);
return;
}
helper(res, head->next);
res.push_back(head->val);
}
};
题目描述:
输入一个链表,按链表从尾到头的顺序返回一个ArrayList。
思路:递归
原文:https://www.cnblogs.com/yejianying/p/jianzhioffer_printListFromTailToHead.html