题目:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
/**
 * 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> result;
        while(head){
            result.push_back(head->val);
            head=head->next;                 //不要写成cur++
        }
        reverse(result.begin(),result.end());
        return result;
    }
};
posted on 2023-07-20 20:22  孜孜不倦fly  阅读(10)  评论(0)    收藏  举报