Remove duplicates from sorted list

自动驾驶仿真基础:使用Veristand自定义CAN报文的Checksum和Counter 文章目录前言一、关于Checksum的组成形式二、自定义的Checksum方法一1、实现的主要流程图如下:2、方法一的主要算法参考三、自定义的Checksum方法二1、软件及插件下载;2、Custom device的使用;4、Veristand调用Custom Device;5、Veristand发送信号值;6、部署到实时机; 前言 1、现在很多的车厂对于车辆的安全机制非常重视,车厂通过对发送的CAN数据进行加密而形成一种保护机制,而Checksum和Counter是其中的一种保护介质,当CAN报文数据的 阅读详情

做leetcode的这两道题,感觉收获还是挺多的,总结一下。


I题题目:

给定一个单链表,删除其中重复数据,使原链表中的数据都只出现一次。


I题没有什么难点,当时做完之后针对链表的题目写了这么几句话:

1.需要几个指针先弄清楚。

2.最后需要返回的指针要预留出来。

后来在Discuss里研究别人的答案,又加了一条:

3.需要把废弃的节点都回收了。麻烦的是如果这么做一般还需要多搞出一个指针。


II题题目:

给定一个单链表,删除其中所有的重复数据,只留下原链表中单独存在的数据。


II题刚开始自己没做出来,主要是按照I题总结的方法做,越做越跑偏。

因为最终的头结点刚开始是不能确定的,如果按照上面的2来做,先要把返回节点确定下来,再继续过程,实在是太麻烦了,不知道要用到多少指针。

后来研究了别人的算法,在Discuss里号称是best c++ solution,刚开始都没看懂····分析了一半天才恍然大悟!

原来双重指针是有这样的作用啊,之前除了课本上要求,还从来没有主动用过双重指针。

大体思路是这样的:(head指针图中用h表示)

    新定义了一个指向head指针的指针runner(图中用r表示)

    1-->1-->1-->2-->3-->nullptr

    h

    r

    用*r(最开始的时候其实就是head)控制指针的后移

    如果满足条件((*runner)->next && (*runner)->val==(*runner)->next->val)则说明等于此值的所有元素需要被删除,即将*r指针后移,开始while循环,直到*runner指向一个新值,继续对上面的条件进行判定。

    1-->1-->1-->2-->3-->nullptr

                     h

                     r

    如果上面的条件不成立,则说明该节点是单一的,属于结果链表,不做处理直接跳过

    重点就在这里,此时不是简单的指针后移,而是将双重指针进行了后移,即runner指向了下一个指针:runner=&((*runner)->next);

    1-->1-->1-->2-->3-->nullptr

                     h

                           r

    所以,在head没有找到返回节点之前,head是一直跟着*runner向后移动的,当head找到了第一个结果节点的时候,runner就更改了指向,指向head指针的下一个节点,之后head就不再移动了。

    此方法可以更好的保持程序的一致性,不需要单独为寻找返回指针而写一段代码,感觉还是很好的。

【Dify系列教程重置精品版】第二章:在Windows上部署Dify 让我们的电脑允许使用Linux系统。有点兴奋是怎么回事?简单来说就是让你的电脑拥有另一个叫做Linux的系统。3.选择“适用于Linux的Windows子系统”与 “虚拟机平台”与“Hyper-V"第1章:安装 wsl (Windows Subsystem for Linux)上一章我们聊了什么是Dify,这一章我们讲一下怎么才能用Dify。好了,我们的环境部署好了,下一章我们正式进入Dify。下载完成后,我们直接一直无脑下一步,安装即可。完成上述步骤,我们就可以开始安装wsl了。我们的虚拟化也是开启的。 阅读详情

相关推荐

EDA课程实验:《数字逻辑电路》实验四___基于Minisys 平台 VIVADO工具与Verilog语言

(4)使用 Verilog HDL 实现一个分频器 clock_div,输入的是系统提供的 100MHz 频率,输出的是 1Hz 频率,占空比是 1:2,(实际上可以用一个加 1 计数器来实现降频,输入的是一个 100MHz 频率的方波,对这 个方波计数 1 亿次刚好到 1 秒(1Hz),题目要求输出频率占空比是 1:2,也就是这个 1Hz 的 方波高电平和低电平各 500ms,可以采用计数到中间值的时候输出电平翻转。(1)1) 拨动 SW1~0 为 01,按下 P4 按钮,GLD1~0 为 01;

ssjy_的博客 1296

leetcode 83和84 Remove Duplicates from Sorted List 和leetcode 1836

删除链表中的结点合集。

weixin_41554427的博客 716

Qwen-Image-2.1本地图像生成整合包:8G显存一键部署指南

文生图模型是AI视觉创作的核心技术,其本地化部署需兼顾模型能力、硬件适配与工程易用性。Qwen-Image-2.1作为支持文本生成、图像编辑与多图参考的统一架构模型,突破了传统Diffusion模型在消费级显卡上的运行瓶颈。通过AWQ量化、vLLM推理优化与ComfyUI节点重构,实现8G显存稳定运行,显著降低CUDA环境配置复杂度。该方案面向设计师、教师与普通用户,提供开箱即用的本地AI图像工作流,适用于电商主图迭代、教学配图生成与IP角色延展等真实场景,让高质量图像生成真正走出云端,落地桌面。

weixin_29082143的博客 397

83. Remove Duplicates from Sorted List*

83. Remove Duplicates from Sorted List* https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 题目描述 Given a sorted linked list, delete all duplicates such that each element appear only once...

珍妮的选择的博客 250

Cadence Allegro16.6怎么导出器件引脚信息的报告

当我们需要用到器件的引脚相关信息时,可以利用allegro中的reports这个功能导出器件的相关信息。下面是具体的操作步骤。

suyucheng66的博客 5738

NotebookLM平替实测:用Open Notebook+Ollama零成本搭建私有AI知识库

本文提供了一份详细的实战指南,教你如何利用Open Notebook与Ollama,在本地零成本搭建一个功能强大且完全私有的AI知识库。通过Docker容器化部署,实现数据绝对安全、模型自由选择与离线运行,是NotebookLM等云端工具的绝佳平替方案,尤其适合注重数据隐私的教育工作者、研究者及小团队。

weixin_29052717的博客 513

leetcode:82. Remove Duplicates from Sorted List II(Java)解答

转载请注明出处:z_zhaojun的博客 原文地址:http://blog.youkuaiyun.com/u012975705 题目地址:https://leetcode.com/problems/reverse-linked-list-ii/ Remove Duplicates from Sorted List II Given a sorted linked list, delete all

z_zhaojun的博客 2157

PromptBio实战:如何用AI对话搞定转录组数据分析(附详细操作截图)

本文详细介绍了如何利用PromptBio平台通过AI对话完成转录组数据分析,无需编程基础即可实现从数据上传到结果解读的全流程。文章包含详细的操作截图和参数配置建议,帮助科研人员快速掌握这一生信分析工具,显著提升研究效率。

weixin_30872157的博客 134

Remove Duplicates from Sorted List

题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 提议

MAGIC_YS的专栏 614

嵌入式代码审计中常见的漏洞(四)

经过漫长时间的迭代更新,内容从一开始的碎片化网罗搜集,到排版与整合划分,再到学习与实践验证,最后摒弃初始,用自己的语言与实践结论通俗的将它展现出来。强化知识技能的同时也为读者带来更好的阅读体验。 本篇介绍了以下代码安全问题: 编号 漏洞 1 敏感信息硬编码 2 未初始化安全 3 越界访问 4 迭代器失效 5 迭代器尾部解引用

武天旭的博客 3317

在MATLAB中将C语言代码转化为可执行的mexw64文件

这样,您可以将高效的C语言算法集成到MATLAB环境中,以便更好地利用MATLAB的功能和特性。请记住,在使用mex转换C语言代码之前,您需要正确编写和测试C语言代码,并确保它与MATLAB的mex接口兼容。MATLAB是一种功能强大的数值计算软件,它提供了一个机制,可以将C语言代码转化为MATLAB可执行的mexw64文件。在上述命令中,"-output"选项指定生成的mex文件的名称,"myfunction"是您选择的名称,"myfunction.c"是要编译的C语言源文件。步骤1:编写C语言代码。

CodeRoarX的博客 1427

[LeetCode] Remove Duplicates from Sorted List、Remove Duplicates from Sorted List II

Remove Duplicates from Sorted List: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->

a83610312的专栏 650

SAP S/4HANA 中 RAP 业务对象接口的消费模式

本文探讨了SAP S/4HANA中RAP业务对象接口的消费模式,重点介绍了通过EML直接调用和CDS投影两种Clean Core开发路径。文章分析了BO Interface作为稳定契约的价值,并提供了BAdI集成、OData服务发布等实际场景案例,同时对比了OData V2/V4的技术选型考量,最后强调了ADT向导使用中的DCL权限注意事项。全文旨在帮助开发者构建升级友好的业务对象消费方案。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 757

LeetCode Remove Duplicates from Sorted List & Remove Duplicates from Sorted List II

Description: Solution:

miss_snow_m的专栏 363

温度PID控制PLC程序

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

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Remove Duplicates from Sorted List II

解题思路,举几个例子 1->1  1->1->2->2 1->2->2->3 1->2->2 思路也就清晰了: 循环遍历每个元素: 1、从头就开始重复的,head直接置为下一个跟头重复元素不同的结点,继续(当然可能还继续重复) 2、不从头重复的,考虑是去掉重复的所有元素,所以要多一个指针,指向重复的第一个结点的前一个 容易出错的地方: 1、判断循环的指针p是否为空  一定

pandafxp的专栏 731

深度学习工具包 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")

[LeetCode80]Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1-

coder 进阶的专栏 3876

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

[Leetcode] Remove Duplicates from Sorted List II

Remove Duplicates from Sorted List II 题解 题目来源:https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/description/ Description Given a sorted linked list, delete all nodes that have dupli...

weixin_30834783的博客 125

82. Remove Duplicates from Sorted List II

82. Remove Duplicates f rom Sorted List II三刷

m0_38141582的博客 209

leetcode 随笔 Remove Duplicates from Sorted List & Remove Duplicates from Sorted List II

Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1-&gt;1-&gt;2 Output: 1-&gt;2 Example 2:Input: 1-&gt;1-&gt;2-&gt;3-&gt;3 Output: 1-&gt;2-&gt;...

Runner_of_nku的博客 1万+

LeetCode(83)Remove Duplicates from Sorted List

题目如下: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 题目分析: 本题是给定一个链表,对链表

BUILD 4142

[leetcode]Remove Duplicates from Sorted List II

新博文地址:[leetcode]Remove Duplicates from Sorted List II http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/   Given a sorted linked list, delete all nodes that have duplicate num...

mc46790090的专栏 156

LeetCode Remove Duplicates from Sorted List

删除一个有序链表中重复的元素。

DRFish 1187

【Remove Duplicates from Sorted List】

Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. Example 1: Input: head = [1,1,2] Output: [1,2] Example 2: Input: head = [1,1,2,3,3] Output: [1,2,3] Constrain

weixin_39400958的博客 309

LeetCode_Remove Duplicates from Sorted List

LeetCode_Remove Duplicates from Sorted List

小胜爱捣鼓 1060
上一篇: leetcode第二遍不需要做的题目
下一篇: c++新技能不断get中
hellofuturecyj
博客等级 码龄16年 3粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值