当前位置:网站首页>【Hot100】19. Delete the penultimate node of the linked list
【Hot100】19. Delete the penultimate node of the linked list
2022-07-01 16:05:00 【Wang Liuliu's it daily】
19. Delete the last of the linked list N Nodes
Medium question

Virtual header node + Double pointer
fast Move first n+1 Step , leading n Nodes , bring slow and fast Interval between n-1 Nodes .
interval n-1 Nodes lead n Nodes .
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */
class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
// Virtual header node
ListNode dummy = new ListNode(0);
dummy.next = head;
ListNode slow = dummy,fast = dummy;
// send slow and fast interval n-1 Nodes
for(int i=0;i<=n;i++){
fast = fast.next;
}
while(fast != null){
slow = slow.next;
fast = fast.next;
}
slow.next = slow.next.next;
return dummy.next;// Returns the entire list
}
}
边栏推荐
- Detailed explanation of stm32adc analog / digital conversion
- How to adjust the size of computer photos to what you want
- Introduction to RT thread env tool (learning notes)
- u本位合约和币本位合约有区别,u本位合约会爆仓吗
- Go language learning notes - Gorm use - table addition, deletion, modification and query | web framework gin (VIII)
- 嵌入式开发:5个修订控制最佳实践
- In the era of super video, what kind of technology will become the base?
- I'm a senior test engineer who has been outsourced by Alibaba and now has an annual salary of 40w+. My two-year career changing experience is sad
- In the past six months, it has been invested by five "giants", and this intelligent driving "dark horse" is sought after by capital
- 学会了selenium 模拟鼠标操作,你就可以偷懒点点点了
猜你喜欢

嵌入式开发:5个修订控制最佳实践

Five years after graduation, I became a test development engineer with an annual salary of 30w+

使用腾讯云搭建图床服务

三星率先投产3nm芯片,上海应届硕士生可直接落户,南开成立芯片科学中心,今日更多大新闻在此...

Detailed explanation of stm32adc analog / digital conversion

圈铁发音,动感与无噪强强出彩,魔浪HIFIair蓝牙耳机测评

【开源数据】基于虚拟现实场景的跨模态(磁共振、脑磁图、眼动)人类空间记忆研究开源数据集

【LeetCode】43. 字符串相乘

Pico,是要拯救还是带偏消费级VR?

picgo快捷键 绝了这人和我的想法 一模一样
随机推荐
vscode 查找 替换 一个文件夹下所有文件的数据
What time do you get off work?!!!
The picgo shortcut is amazing. This person thinks exactly the same as me
硬件开发笔记(九): 硬件开发基本流程,制作一个USB转RS232的模块(八):创建asm1117-3.3V封装库并关联原理图元器件
Redis seckill demo
有些能力,是工作中学不来的,看看这篇超过90%同行
Zero copy technology of MySQL
Nuxt. JS data prefetching
Seata中1.5.1 是否支持mysql8?
ADS算力芯片的多模型架构研究
Please, stop painting star! This has nothing to do with patriotism!
Introduction to RT thread env tool (learning notes)
process.env.NODE_ENV
Some abilities can't be learned from work. Look at this article, more than 90% of peers
How to adjust the size of computer photos to what you want
How to adjust the color of the computer screen and how to change the color of the computer screen
Overview | slam of laser and vision fusion
Pico, can we save consumer VR?
Comment win11 définit - il les permissions de l'utilisateur? Win11 comment définir les permissions de l'utilisateur
表格存储中tablestore 目前支持mysql哪些函数呢?