【简单】面试题06. 从尾到头打印链表

ubuntu-25.04-desktop-amd64 工具VMware-tools 正确安装方法 摘要:Ubuntu 25.04虚拟机安装VMware Tools后无法实现主机与虚拟机间的文件复制粘贴和拖拽功能,问题可能源于工具兼容性。建议优先安装open-vm-tools套件(含open-vm-tools-desktop),而非官方VMware Tools。具体方案:通过终端执行安装命令后重启系统。该方法已实测有效解决该兼容性问题。(149字) 阅读详情

【题目】
输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。
来源:leetcode
链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/
【示例】
输入:head = [1,3,2]
输出:[2,3,1]
【限制】
0 <= 链表长度 <= 10000
【思想】
借助栈完成,先从头到尾访问链表,在访问的过程中让节点数字进栈,当链表访问完之后,所有的数字都在栈内,然后依次出栈压入vector数组中。
【代码】

class Solution {
public:
    vector<int> reversePrint(ListNode* head) {
        vector<int> v;
        stack<int> s;
        while(head){
            s.push(head->val);
            head=head->next;
        }
        while(!s.empty()){
            v.push_back(s.top());
            s.pop();
        }
        return v;
    }
};
LLC谐振变换器软启动,不只是“慢启动”,还是“智能启动” LLC谐振变换器的软启动,不只是“慢慢来”,而是要在控制时序、限流、响应速度之间精妙权衡。而数字控制,特别是用查表法或混合信号法,为实现真正的“最佳轨迹”提供了可能。✨小Tips:如果你的系统成本敏感,选择查表法准没错;如果你的设计目标是超高速响应,那就上混合信号的高配方案! 阅读详情

相关推荐

从3D相机数据到三维模型:Halcon实战深度图、亮度图与点云转换全流程

本文详细解析了如何利用Halcon将3D相机采集的深度图、亮度图转换为三维点云模型的完整流程。通过实战案例分享,涵盖数据格式处理、点云生成方法(SDK接口与纯Halcon实现)、三维模型可视化优化等关键技术,帮助工程师解决工业检测中的实际难题,提升三维重建精度与效率。

weixin_42525005的博客 400

【Python】【难度:简单】Leetcode 面试题06. 从尾到头打印链表

输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 限制: 0 <= 链表长度 <= 10000 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 # Definition for...

thomashhs12的博客 255

snipersim安装

snipersim安装记录,便于后续使用tip:snipersim需要在python2的环境下编译。

weixin_53507617的博客 924

剑指offer 面试题06. 从尾到头打印链表 [简单]——容器、递归

我的解题: 1.遍历链表,将数值保存在vector<int> ptr中,再反向遍历ptr /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL...

Vermouth_Su的博客 188

激光三角测量法:斜射与直射式技术的原理与应用解析

本文深入解析激光三角测量法中斜射式与直射式技术的原理、应用及对比。斜射式适用于高精度小范围测量,尤其擅长处理反光表面;直射式则适合大范围位移检测,结构更简单。文章详细介绍了两种技术的光路分析、数学建模、应用场景及选型建议,并探讨了系统校准与误差分析方法,为工业检测领域提供实用参考。

weixin_29280219的博客 418

Matplotlib图片尺寸调整全攻略:从figsize到savefig的实战技巧

在数据可视化与科学计算中,图形尺寸控制是影响图表可读性与专业度的基础环节。其核心原理在于协调逻辑尺寸(英寸)与物理输出(像素)的映射关系,这直接决定了信息呈现的清晰度与布局合理性。从技术价值看,精准的尺寸控制能提升图表在不同媒介(如学术论文、报告、网页)中的适配性,避免显示不全、模糊失真等常见问题。在应用场景上,无论是Jupyter Notebook中的交互探索、自动化报告的批量生成,还是满足严格出版要求的插图制作,都需要掌握对应的尺寸调整策略。本文聚焦于matplotlib中的figsize参数、rcPa

weixin_30899023的博客 342

剑指offer面试题06. 从尾到头打印链表

题目 https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/ 思路 遍历链表到数组 然后反转后返回即可 代码 /** * * @date: 2020-03-10 22:00 * @param: * @param head: * @return: * @retu...

WenHaiGo的博客 231

基于ROS2 Humble与Livox Mid-360的双雷达点云融合实战解析

本文详细解析了基于ROS2 Humble与Livox Mid-360的双雷达点云融合实战方案。从环境搭建、驱动安装、双雷达配置、外参标定、时间同步到点云融合核心实现,全面介绍了技术要点与避坑指南,并提供了工程化部署与性能优化建议,助力开发者高效实现高精度点云合成应用。

ss78901的博客 1105

4种方法详解:剑指Offer 06. 从尾到头打印链表

原题LeetCode链接:剑指Offer 06. 从尾到头打印链表 题目:剑指Offer 06. 从尾到头打印链表 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例1: 输入:head = [1,3,2] 输出:[2,3,1] 0 <= 链表长度 <= 10000 思路一:reverse()方法 ​ 遍历链表,将遍历到的元素依次插入到vector中,然后调用reverse方法反转即可。时间复杂度:O(n),空间复杂度:O(1)。C++代码如下: class Solu

点滴初学者的博客 5444

从零到一:华为iMaster NCE-Campus部署中的Euler OS与FusionInsight深度解析

本文深入解析华为iMaster NCE-Campus部署中Euler OS与FusionInsight的关键技术要点,包括RAID配置、网络绑定技术、安装避坑指南及性能调优方案。通过实战经验和详细配置示例,帮助工程师提升部署效率与系统稳定性,确保华为企业级解决方案的高效运行。

f6g7h8i9j的博客 552

扩散模型与强化学习(13):In-Context Reward Hacking现象与解决方案

奖励作弊(Reward Hacking)指智能体通过钻规则漏洞而非真正完成任务来最大化奖励信号。以论文编辑实验为例,研究提出“上下文奖励作弊”(ICRH)概念,即模型利用共享上下文钻空子,如盲目添加“正确!”或输出无关内容。实验发现,模型规模扩大可能加剧ICRH,且提示词优化难以根治。与传统奖励作弊不同,ICRH发生在部署阶段,由通用性驱动。应对建议包括多轮测试、多样化反馈及异常场景模拟,但尚无完美解决方案。

沉迷单车的追风少年 1323

剑指Offer 面试题06. 从尾到头打印链表

剑指Offer 面试题06. 从尾到头打印链表

TrueDei 1111

AI驱动的客户终身价值分析:深入理解公司的收入质量

客户终身价值(Customer Lifetime Value, CLV)是衡量客户在整个生命周期内能为企业带来多少利润的重要指标。传统的CLV计算方法往往过于简化,无法准确反映复杂的客户行为和收入模式。本文旨在介绍如何利用人工智能技术,特别是机器学习方法,构建更精确的CLV预测模型,从而帮助企业深入理解其收入质量。CLV的基本概念和商业意义传统CLV计算方法的局限性基于机器学习的CLV预测方法特征工程和模型选择策略实际应用案例和Python实现首先介绍CLV的基本概念和商业背景。

AI云原生与云计算技术学院 480

面试题06:从尾到头打印链表

文章目录面试题 6:从尾到头打印链表题目描述思路一:栈思路二:递归思路三:集合的 reverse 方法 面试题 6:从尾到头打印链表 题目描述 输入一个链表的头结点,按照 从尾到头 的顺序返回节点的值。 返回一个 ArrayList。 如果修改链表结构,可以先利用头插法将链表逆置,然后再依次输出结点。这个方法在 “面试题24:反转链表” 中会用到 不修改链表结构,主要就利用栈“后进先出”的特性...

charlsonzhao的博客 276

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

LeetCode | 面试题06. 从尾到头打印链表【剑指Offer】【Python】

LeetCode 面试题06. 从尾到头打印链表【剑指Offer】【Easy】【Python】【链表】 问题 力扣 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 限制: 0 <= 链表长度 <= 10000 思路 解法一 reverse函数 时间复杂度: O(n),n为 head 链表长...

Wonz 741

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

剑指offer系列——剑指 Offer 06. 从尾到头打印链表(C语言)

⭐️前面的话⭐️ 大家好!博主开辟了一个新的专栏——剑指offer,我要开始刷题了!这个专栏会介绍《剑指offer》书上所有的面试编程题。并且会分享一些我的刷题心得。由于博主水平有限,如有错误,欢迎指正,如果有更好的解题思路和算法可以分享给博主哦!一起加油!一起努力! 剑指 Offer 06. 从尾到头打印链表(C语言)

未见花闻的博客 1096

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

面试题06. 从尾到头打印链表

题目: 面试题06. 从尾到头打印链表 题解: 1. 题解一: 用一个指针遍历链表长度得出数组容量,然后从数组的最后一位开始填充。 2. 题解二: 反转链表,同时记录链表长度,翻转完成后创建数组,用翻转后的链表给数组赋值,返回数组。 代码: 1. 代码一: /** * 面试题06 */ public class 面试题06 { // 解法1: public static i...

dev_zyx的博客 380

剑指 offer 面试题精选图解 06 . 从尾到头打印链表

点击上方“图解面试算法”,选择“星标”公众号重磅干货,第一时间送达今天分享的题目来源于 LeetCode 上的剑指 Offer 系列 06 . 从尾到头打印链表。题目链接:https:/...

程序员吴师兄的博客 575

Java详解剑指offer面试题06--从尾到头打印链表

Java详解剑指offer面试题6–从尾到头打印链表 输入一个链表的头节点,从尾到头打印链表每个节点的值。 使用栈 我的做法:典型的后进先出,使用栈,顺序遍历一遍链表,依次将每个值入栈。得到的就是尾节点在前,头节点在后的列表。 package Chap2; import java.util.LinkedList; import java.util.ArrayList; public class FromTail2Head { // 节点类的定义 private class List

快乐李同学的博客 532

面试题06. 从尾到头打印链表【LeetCode剑指offer】

题目: 面试题06. 从尾到头打印链表 思路: 两次遍历链表,第一次得到链表的 length ; 定义一个返回数组,长度为 链表的 length ; 为数组反向赋值,赋值完成,也就将链表反向存储到数组中。 实现: /** * Definition for singly-linked list. * public class ListNode { * int val; * ...

江璇Up 550

剑指Offer_06_从尾到头打印链表

package 二刷; import 二刷.common.ListNode; import java.util.ArrayList; import java.util.Stack; /** * https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/ * * @author Qitong!! * @Date 2020/6/30 */ public class 剑指Offer_06_从尾到头打印链表 {

qitong啊的博客 525

LeetCode - 面试题06 - 从尾到头打印链表

一 目录 不折腾的前端,和咸鱼有什么区别目录一 目录二 题目三 解题思路四 统计分析五 解题套路二 题目 输入一个链表的头节点, 从尾到头反过来返回每个节点的值(用数组返回)。 示例 ...

weixin_41806099的博客 341

leetcode.剑指 Offer 06. 从尾到头打印链表

剑指 Offer 06. 从尾到头打印链表 难度简单36收藏分享切换为英文关注反馈 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 限制: 0 <= 链表长度 <= 10000 通过次数52,444提交次数68,914 在真实的面试中遇到过这道题? 是 否 《剑指 Offer(第 2 版)》官方授权 /** * Definition for singly-li..

eilot_c的博客 313

剑指Offer LeetCode 面试题06. 从尾到头打印链表

面试题06. 从尾到头打印链表 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 解题 利用Stack栈先进后出的特征 import java.util.Arrays; import java.util.Stack; class Solution { static public int[] reversePrint(ListNode head) { Stack<Integer&

TrueDei 1206

【LeetCode-剑指Offer】06. 从尾到头打印链表

一、题目 二、解决 1、 思路: 代码: 时间复杂度: O(n)O(n)O(n) 空间复杂度: O(n)O(n)O(n) 2、 思路: 代码: 时间复杂度: O(n)O(n)O(n) 空间复杂度: O(n)O(n)O(n) 3、 思路: 代码: 时间复杂度: O(n)O(n)O(n) 空间复杂度: O(n)O(n)O(n) 三、参考 1、 2、 3、 ...

HeavenDan的博客 292

剑指 Offer 06. 从尾到头打印链表

剑指 Offer 06. 从尾到头打印链表 难度简单38收藏分享切换为英文关注反馈 输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 限制: 0 <= 链表长度 <= 10000 解答: public static int[] reversePrint(ListNode head) { if (head == null) { re...

ZhaoXia_hit的博客 160
上一篇: 【简单】461. 汉明距离
下一篇: 【简单】620. 有趣的电影
菜菜2022
博客等级 码龄10年 67粉丝 1033原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址