/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> m_v;
vector<int> printListFromTailToHead(ListNode* head) {
// 采用递归,先输出其后面节点,在输出自己
if (head) {
printListFromTailToHead(head->next);
m_v.push_back(head->val);
}
return m_v;
}
};
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
class Solution {
public:
vector<int> m_v;
vector<int> printListFromTailToHead(ListNode* head) {
// 采用递归,先输出其后面节点,在输出自己
if (head) {
printListFromTailToHead(head->next);
m_v.push_back(head->val);
}
return m_v;
}
};