您的位置:首页 > Web前端

offer - 06 - 从尾到头打印链表

2017-09-13 01:10 267 查看

问题描述

解题思路

实现源码

/**
*  struct ListNode {
*        int val;
*        struct ListNode *next;
*        ListNode(int x) :
*              val(x), next(NULL) {
*        }
*  };
*/
class Solution {
public:
vector<int> printListFromTailToHead(ListNode* head) {
vector<int> temp,result;

struct ListNode *node = head;

while(node != NULL) {
temp.push_back(node->val);
node = node->next;
}

reverse(temp.begin(),temp.end());
return temp;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: