LeetCode解题报告--Remove Nth Node From End of List

zedboard(5)spi轮询和中断 一个SPI可以有几个从设备 在程序中使用 s32 XSpiPs_SetSlaveSelect(XSpiPs *InstancePtr, u8 SlaveSel) 选择。其实就是吧对应设备的ss拉低。 备注:只选一个ss,可以不用指定。(感觉,还没测试) 这是xspips.c中定义的函数,发送和接收有 XSpiPs_Transfer 和 XSpiPs_PolledTransfer 两个函数,分别采用中断和轮询模式。    一、轮询模式 米联客参考代码,SpiPs_Init中部分和官方例程流程一样,Spi 阅读详情

**题目:**Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.

For example,

Given linked list: 1->2->3->4->5, and n = 2.

After removing the second node from the end, the linked list
becomes 1->2->3->5.

Note:
Given n will always be valid.
Try to do this in one pass.
原题链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/
分析:改题要求从List删除倒数第N个元素。
解题思路找到倒数第N个元素,修改指针的指向,那么问题来了,如何找到第N个元素?
1)定义两个)ListNode对象(C/C++ 指针:p,q,开始指向List头指针head,
2)p指针开始移动N个位置,此时p-q的长度差为N,现在很自然的想法,整体移动p,q两个对象,知道p移动到最后一个原素(尾指针),此时,q指向的下一个元素即为要删除的(倒数第N个)元素。

Java Accepted 代码:

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode p = head;//Faster pointer
        ListNode q = head;//Slower pointer

        if(head.next == null){
            return null;
        }

        //Faster pointer first travel n nodes
        for(int i = 0;i < n;i ++){
            p = p.next;
        }
        if(p == null){
            head = q.next;
            return head;
        }
        //When p.next == null, q points the node that required
        while(p.next != null){
            p = p.next;
            q = q.next;
        }

        q.next = q.next.next;
        return head;
    }
}

相关代码放在个人github:https://github.com/gannyee/LeetCode/

ksz9031 mmd读取不了_ZYNQ. LwIP.PHY.KSZ9031RNX 新一块板子米尔科技的z-turn 使用的PHY芯片是Micrel的 KSZ9031RNX 而不是zedboard上的Marvell的。直接使用lwip的echo server demo时会报错 , 无法启动。在网上找了很久终于找到几篇关于这个问题的文章。修改PHY的驱动xemacpsif_physpeed.c文件该芯片的PHY Identifier 是 0x0022bsp设置中修改参数以提速MEM... 阅读详情

相关推荐

对比学习损失函数避坑指南:为什么你的自监督模型不收敛?

本文深入剖析对比学习损失函数中的关键陷阱,揭示自监督模型不收敛的根本原因。通过分析温度系数选择、负样本采样策略和特征归一化等核心因素,提供实用解决方案。实验数据表明,正确设置温度系数τ(建议0.07起)可提升30%性能,而MoCo风格的负样本队列比SimCLR方案在小批量时准确率高6-8%。

nokia的博客 922

LeetCode: Remove Nth Node From End of List 解题报告

Remove Nth Node From End of List  Total Accepted: 46720 Total Submissions: 168596My Submissions Question Solution    Given a linked list, remove the nth node from the end of list and...

weixin_33815613的博客 122

RK3566开发板实战:YT8512C百兆网卡调试全记录(附DTS配置避坑指南)

本文详细记录了RK3566开发板上YT8512C百兆以太网卡的调试全过程,包括硬件信号检测、DTS配置优化及常见错误排查。特别针对DTS配置中的关键参数和避坑指南进行了深入解析,为开发者提供实用的调试技巧和经验分享。

weixin_29189381的博客 267

leetcode解题报告19. Remove Nth Node From End of List

leetcode解题报告19. Remove Nth Node From End of List题目地址 难度是medium题目描述给定一个链表,只有头指针,和一个数字n。要求把倒数第n个数给删掉。最后删除后链表的头指针。我的思路题目本身是很简单的,是数据结构层面的题目。最简单思路是先遍历一遍链表,看它的长度,然后可以算出实际要删除的位置。然后第二次遍历就可以把它删掉了。 但是题目有建议只遍历一次

sysu_xiaoming的博客 247

先楫HPM6E00EVK EtherCAT从站配置与CIA402 8轴运动控制实战解析

本文详细解析了先楫HPM6E00EVK开发板的EtherCAT从站配置与CIA402 8轴运动控制实战。从环境准备、XML文件配置、代码移植到TwinCAT工程设置,提供了完整的移植指南,帮助开发者实现高效的多轴同步运动控制。

o5p6q的博客 415

网络攻防技术——MD5碰撞试验

一、题目 本次实验主要是加深大家对MD5碰撞及其原理的理解,使用SEED实验环境中的工具及编程语言,完成以下任务: a)使用md5collgen生成两个MD5值相同的文件,并利用bless十六进制编辑器查看输出的两个文件,描述你观察到的情况; b)参考Lab3_task2.c的代码,生成两个MD5值相同但输出不同的两个可执行文件。 c)参考Lab3_task3.c的代码,生成两个MD5值相同但代码行为不相同的可执行文件。 d)回答问题:通过上面的实验,请解释为什么可以做到不同行为的两个可执行文件具有相同的M

学习记录 3620

LeetCode 19. Remove Nth Node From End of List 解题报告

LeetCode 19. Remove Nth Node From End of List 解题报告题目描述Given a linked list, remove the nth node from the end of list and return its head. 示例Example 1: Given linked list: 1->2->3->4->5, and n = 2. Afte

骆小坑的填坑之旅 1241

基于步科(Kinco HMI 2.5)的组态软件使用

本篇介绍Kinco HMI 2.5的组态软件使用,图标如下 目录   一、新建工程并配置连接 1.1 根据工程选择PLC与HMI型号 1.2 配置PLC连接与选项 二、组态画面编辑 2.1 打开画面窗口 2.2 编辑画面 2.3 组态变量与PLC程序变量连接 三、组态程序下载到HMI 3.1 连接 3.2 编译 3.3 下载 一、新建工程并配置连接 1.1 根据工...

ACanswer的专栏 1万+

[LeetCode] Remove Nth Node From End of List 解题报告

Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linke

codingtmd_in_china的博客 204

BES2700的PMU

BES2700ZP-BES2700芯片的PMU架构分析摘要:本文档分析了BES2700芯片的电源管理单元(PMU)架构。实际应用中仅需为VBAT引脚供电,其余电源均由芯片内部PMU提供。文档包含架构示意图、问题列表和参考链接,涉及PMU工作原理、外部供电要求等关键技术点。待解决问题包括具体供电参数和内部电源转换机制等。通过添加日志信息和代码片段,为开发人员提供了调试PMU功能的实用方法。

云淡风轻 117

使用 Simulink + Simscape Electrical 实现一个变压器耦合式单相全波整流器的仿真模型

本文介绍了基于Simulink的变压器耦合式单相全波整流器建模与仿真方法。详细说明了从项目创建、模块添加、电路搭建到参数配置的完整建模过程,重点分析了整流器的效率与损耗特性,包括变压器损耗和二极管导通损耗。通过仿真展示了输入输出波形特征,并提出了选用高效元件、优化变压器设计等改进建议。该案例为电力电子系统建模提供了实用参考,有助于深入理解整流电路工作原理和性能优化方法。

amy_mhd的博客 185

【LeetCode】19. Remove Nth Node From End of List 解题报告(Python)

题目分析: 给定链表,从链表末尾删除倒数第n个节点并返回新的头部。由于题目要求遍历一次完成操作所以不可能找到长度在删除。借鉴网上的一种做法,设置两个指针。前面的指针走n个元素,后面的指针再走。这样前面的走到最后时后面的指针刚好指到要删除的前一个元素。 代码说明: 1、前面元素走n次 for i in range(n): begin = begin.next 2、如果前面指针走完是空了,那么要删除的...

L141210113的专栏 545

基于NB-IoT的智慧路灯监控系统(NB-IoT专栏—实战篇1:项目简介)

基于NB-IoT技术的城市道路智慧路灯监控系统,在每个照明节点上安装一个集成了NB-IoT模组的单灯控制器,单灯控制器再经运营商的网络,与路灯控制平台实现双向通信,路灯控制平台直接对每个灯进行控制,包括开关灯控制、光照检测、自动调节明暗、电耗分析等操作。

不脱发的程序猿 5万+

[leetcode] 19. Remove Nth Node From End of List 解题报告

题目链接:https://leetcode.com/problems/remove-nth-node-from-end-of-list/ Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2

小榕流光的专栏 453

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

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

[LeetCode 解题报告]019.Remove Nth Node From End of List

Given a linked list, remove then-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, t...

CVer 129

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

[leetcode019] Remove Nth Node From End of List 解题报告

[leetcode019] Remove Nth Node From End of List 解题报告 Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1-&gt;2-&gt;3-&gt;4-&gt;5, and n ...

初沏的茶的博客 249

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

LeetCode解题报告—— 4Sum & Remove Nth Node From End of List & Generate Parentheses

1. 4Sum Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target. Note:Th...

dbvz4901的博客 112

Leetcode解题报告:Remove Nth Node From End of List

题目 Remove Nth Node From End of List Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4...

weixin_33998125的博客 101

[Leetcode] 19. Remove Nth Node From End of List 解题报告

题目: Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the

魔豆(Magicbean)的博客 370

Leetcode 每日一题:Remove Nth Node From End of List

Leetcode 19: Google 高频面试题 Remove Nth Node From End of List

2401_85421495的博客 1127

Leetcode1-100: 19. Remove Nth Node From End of List

Leetcode1-100: 19. Remove Nth Node From End of List问题描述解题思路代码实现复杂度分析分析 问题描述 Given a linked list, remove the n-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n = 2. After removing the second node

Y123iwantit的博客 183

19. Remove Nth Node From End of List**

19. Remove Nth Node From End of List** https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 题目描述 Given a linked list, remove the n-th node from the end of list and return its head. Example:...

珍妮的选择的博客 251

LeetCode 19 Remove Nth Node From End of List

LeetCode 19 Remove Nth Node From End of List 题目链接 Given the head of a linked list, remove the nth node from the end of the list and return its head. Follow up: Could you do this in one pass? Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] E

旺崽的博客 2448

Remove Nth Node From End of List--LeetCode

1.题目Remove Nth Node From End of List Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removi

涛爸的博客 267

LeetCode [链表] 19.Remove Nth Node From End of List (C++和Python实现)

19.Remove Nth Node From End of List [难度:中等] 【题目】 Given a linked list, remove then-th node from the end of list and return its head. Example: Given linked list: 1->2->3->4->5, and n =...

咸鱼夏の翻身观察记录 284
上一篇: LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结
下一篇: LeetCode解题报告--Valid Parentheses
YatKam
博客等级 码龄12年 58粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值