牛客网-《剑指offer》-从尾到头打印链表
题目: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 };
找我内推: 字节跳动各种岗位
作者:
ZH奶酪(张贺)
邮箱:
cheesezh@qq.com
出处:
http://www.cnblogs.com/CheeseZH/
*
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。