时间: 2020-11-23|55次围观|0 条评论

题目:http://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035

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 };

 

转载于:https://www.cnblogs.com/CheeseZH/p/5110551.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/96955662

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《牛客网-《剑指offer》-从尾到头打印链表
   

还没有人抢沙发呢~