当前位置:网站首页>NC53 删除链表的倒数第n个节点
NC53 删除链表的倒数第n个节点
2022-08-09 13:02:00 【syc596】
NC53 删除链表的倒数第n个节点
删除链表的倒数第n个节点_牛客题霸_牛客网 (nowcoder.com)
//11
//快慢指针
import java.util.*;
public class Solution {
public ListNode removeNthFromEnd (ListNode head, int n) {
ListNode slow=head;
ListNode fast=head;
for(int i=0;i<n;i++){
fast=fast.next;
}
//要删除的节点是头节点
if(fast==null){
return head.next;
}
while(fast!=null&&fast.next!=null){
slow=slow.next;
fast=fast.next;
}
slow.next=slow.next.next;
return head;
}
}
// //长度统计
// import java.util.*;
// public class Solution {
// public ListNode removeNthFromEnd (ListNode head, int n) {
// ListNode cur=head;
// int len=0;
// while(cur!=null){
// len++;
// cur=cur.next;
// }
// if(len-n==0){
// return head.next;
// }
// cur=head;
// for(int i=0;i<len-n-1;i++){
// cur=cur.next;
// }
// cur.next=cur.next.next;
// return head;
// }
// }边栏推荐
- Map mixed density function and quantile added line
- 搭建大型分布式服务(四)Docker搭建开发环境安装Mysql
- 联通网管协议框图
- R language kaggle game data exploration and visualization
- 5G China unicom 一般性异常处理
- Deep Learning Based on R Language - Simple Regression Case
- 【NVIDIA】Tesla V100安装NVIDIA-Driver驱动程序适配CUDA-Toolkit-11.6
- Time series analysis course lab report
- 面试攻略系列(四)-- 你不知道的大厂面试
- 5G 联通网管设计思路
猜你喜欢

5G 联通网管设计思路
![[极客大挑战 2019]Upload](/img/ed/062a89797c790189d9bd77b50335b0.png)
[极客大挑战 2019]Upload

Explanation of RTSP protocol

19、学习MySQL 索引

IDEA Gradle 常遇问题(二)(持续更新)

5G Unicom Network Management Design Ideas

Come and throw eggs.

The sword refers to the offer, cuts the rope 2

FFmpeg多媒体文件处理(ffmpeg操作目录及list的实现)

How to solve the 0x80070005 error when the computer is reinstalled and the system is restored
随机推荐
Standing wave ratio calculation method
jenkins api create custom pipeline
万物皆可柯里化的 Ramda.js
ftplib+ tqdm 上传下载进度条
蓝桥杯线上模拟赛——Flex 经典骰子布局
阿里大淘系模型治理阶段性分享
RTSP协议的实现
群组行动控制--自动队列化实现策略
Sandbox中的进程/线程相关-2
LeetCode 37. Solve Sudoku
CPU-MIPS32 instruction architecture (unlocked pipeline microprocessor)
Professor Chen Qiang "application in machine learning and R" course chapter 17
error Trailing spaces not allowed no-trailing-spaces 9:14 error Unexpected trailing comma
用plot_hist_numeric()实现画直方图
telnet+ftp 对设备进行 操控 和 升级
Microsoft 10/11 命令行打开系统设置页(WUAP,!WIN32)
offset、client、scroll、window.pageYOffset比较
GIN初探,环境安装
ftplib+ tqdm upload and download progress bar
Rmarkdown Tutorial