首页 > 其他 > 详细

牛客网-《剑指offer》-从尾到头打印链表

时间:2016-01-07 17:59:20      阅读:291      评论:0      收藏:0      [点我收藏+]

C++

 1 /**
 2 *  struct ListNode {
 3 *        int val;
 4 *        struct ListNode *next;
 5 *        ListNode(int x) :
 6 *              val(x), next(NULL) {
 7 *        }
 8 *  };
 9 */
10 class Solution {
11 public:
12     vector<int> printListFromTailToHead(struct ListNode* head) {
13         vector<int> res;
14         vector<int>::iterator it;
15         ListNode *idx = head;
16         while (idx) {
17             it = res.begin();
18             res.insert(it, idx->val);
19             idx = idx->next;
20         }
21         return res;
22     }
23 };

 

牛客网-《剑指offer》-从尾到头打印链表

原文:http://www.cnblogs.com/CheeseZH/p/5110551.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!