当前位置:网站首页>【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
}
}
边栏推荐
- When ABAP screen switching, refresh the previous screen
- Introduction to RT thread env tool (learning notes)
- What is the forkjoin framework in the concurrent programming series?
- How does win11 set user permissions? Win11 method of setting user permissions
- 七夕表白攻略:教你用自己的专业说情话,成功率100%,我只能帮你们到这里了啊~(程序员系列)
- HR interview: the most common interview questions and technical answers
- Win11如何设置用户权限?Win11设置用户权限的方法
- 三星率先投产3nm芯片,上海应届硕士生可直接落户,南开成立芯片科学中心,今日更多大新闻在此...
- 求求你们,别再刷 Star 了!这跟“爱国”没关系!
- July 1, 2022 Daily: Google's new research: Minerva, using language models to solve quantitative reasoning problems
猜你喜欢
Automatique, intelligent, visuel! Forte conviction des huit conceptions derrière la solution sslo
近半年内连获5家“巨头”投资,这家智能驾驶“黑马”受资本追捧
[video memory optimization] deep learning video memory optimization method
u本位合约和币本位合约有区别,u本位合约会爆仓吗
For the sustainable development of software testing, we must learn to knock code?
Malaysia's Star: Sun Yuchen is still adhering to the dream of digital economy in WTO MC12
嵌入式开发:5个修订控制最佳实践
What time do you get off work?!!!
ATSs: automatically select samples to eliminate the difference between anchor based and anchor free object detection methods
Idea start command line is too long problem handling
随机推荐
Do280 management application deployment - pod scheduling control
2023 spring recruitment Internship - personal interview process and face-to-face experience sharing
C#/VB.NET 合并PDF文档
ADS算力芯片的多模型架构研究
【开源数据】基于虚拟现实场景的跨模态(磁共振、脑磁图、眼动)人类空间记忆研究开源数据集
马来西亚《星报》:在WTO MC12 孙宇晨仍在坚持数字经济梦想
周少剑,很少见
How does win11 set user permissions? Win11 method of setting user permissions
Some abilities can't be learned from work. Look at this article, more than 90% of peers
IM即時通訊開發實現心跳保活遇到的問題
【LeetCode】43. String multiplication
毕业后5年,我成为了年薪30w+的测试开发工程师
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
Summer Challenge harmonyos canvas realize clock
What is the forkjoin framework in the concurrent programming series?
2023届春招实习-个人面试过程和面经分享
The latest NLP game practice summary!
搜索框和按钮缩放时会有缝隙的bug
Idea start command line is too long problem handling
超视频时代,什么样的技术会成为底座?