Posted on

Description

Submission

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
    vector<int> rets;

    void util(ListNode* head) {
        if(head == nullptr) return;
        util(head->next);
        rets.push_back(head->val);
    }
public:
    vector<int> reversePrint(ListNode* head) {
        util(head);
        return rets;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *