题目: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 };

 

相关文章:

  • 2021-11-16
  • 2021-11-02
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-04
  • 2021-06-17
  • 2021-09-09
  • 2021-12-28
  • 2021-05-01
  • 2021-08-11
  • 2022-02-13
相关资源
相似解决方案