AcWing
  • 首页
  • 题库
  • 题解
  • 分享
  • 问答
  • 活动
  • 应用
  • 吐槽
  • 登录/注册

17,从尾到头打印链表

作者: 作者的头像   Fingerscrossed ,  2021-01-02 10:13:48 ,  阅读 63


-1


从尾到头打印链表(vector反向 迭代器)

https://www.acwing.com/problem/content/18/

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */

class Solution {
public:
    vector<int> printListReversingly(ListNode* head) {
        vector<int>res;
        while(head!=NULL)
        {
            res.push_back(head->val);
            head = head->next;
        }
        return vector<int>(res.rbegin(),res.rend());
    }
};

0 评论

你确定删除吗?

© 2018-2021 AcWing 版权所有  |  京ICP备17053197号-1
联系我们  |  常见问题
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息