题目:
/**
* 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;
ListNode* cur=new ListNode(NULL); #创建虚拟头结点
cur->next=head; #cur->next指向头结点
while(cur->next){
result.push_back(cur->next->val);
cur=cur->next; #不要写成cur++
}
reverse(result.begin(),result.end());
return result;
}
};
标签:ListNode,cur,val,Offer,next,链表,result,06
From: https://www.cnblogs.com/fly-smart/p/17569580.html