递归法

/**
*  struct ListNode {
*        int val;
*        struct ListNode *next;
*        ListNode(int x) :
*              val(x), next(NULL) {
*        }
*  };
*/
class Solution {
public:
    vector<int> v;
    void reverseList(ListNode* head)
    {
        if(!head)
        {
            return;
        }
        reverseList(head->next);
        v.push_back(head->val);
    }
    vector<int> printListFromTailToHead(ListNode* head) {
       reverseList(head);
       return v;
    }
};