/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x), next(NULL) {
* }
* };
*/
#include <vector>
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> result;
ListNode *pCur = head;
while(pCur){
result.push_back(pCur->val);
pCur = pCur->next;
}
reverse(result.begin(), result.end());
return result;
}
};
JZ6_从头到尾打印链表
最新推荐文章于 2024-08-18 12:51:45 发布