题目:
题解:
按题意模拟即可。
代码如下:
/**
* 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) {
ListNode *p=head;
vector<int> res;
while(p){
res.push_back(p->val);
p=p->next;
}
reverse(res.begin(),res.end());
return res;
}
};