---- prove safety OFFERs face questions from the tail to the head 06. Print list

Links: https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/

 

Code:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    vector<int> reversePrint(ListNode* head) {
        vector<int> res;
        while (head) {
            res.push_back(head->val);
            head = head->next;
        }
        return vector<int>(res.rbegin () res.rend ()); 
    } 
};

 

 

Guess you like

Origin www.cnblogs.com/clown9804/p/12312843.html