当前位置:网站首页>LeetCode 19. Delete the Nth last node of the linked list
LeetCode 19. Delete the Nth last node of the linked list
2022-08-10 11:57:00 【Mizuna pen】
Original URLhttps://leetcode.cn/problems/remove-nth-node-from-end-of-list/
Delete the nth last node;
public ListNode removeNthFromEnd(ListNode head, int n) {// The first one may be deleted, so refer to the virtual nodeListNode dummyHead = new ListNode(-1);dummyHead.next = head;ListNode cur = dummyHead;ListNode prev = dummyHead;while(cur != null) {// The difference is n+1 nodes, so here is the condition of n<0if(n<0) {prev = prev.next;}n--;cur = cur.next;}prev.next = prev.next.next;return dummyHead.next;}
边栏推荐
- HDU 4135:Co-prime (容斥原理)
- LeetCode 82. 删除排序链表中的重复元素 II
- Clicking Exercise - 64 Longest Harmonic Subsequences
- StoneDB 文档捉虫活动第一季
- Article take you understand interrupt the key driver of polling mechanism
- If someone asks you about distributed transactions again, throw this to him
- LeetCode_152_乘积最大子数组
- 中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
- 模块九 - 设计电商秒杀系统
- LeetCode_628_三个数的最大乘积
猜你喜欢
2022年裁员潮,失业程序员何去何从?
什么是幂等性?四种接口幂等性方案详解!
CPU多级缓存与缓存一致性
即时零售业态下如何实现自动做账?
[Go WebSocket] 多房间的聊天室(一)思考篇
Where can I view the version record of WeChat applet submission review history?
StoneDB 文档捉虫活动第一季
零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?
电脑怎么设置屏幕息屏时间(日常使用分享)
Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control
随机推荐
【小程序 | 启航篇】一文打通任督二脉
常量及数据类型你还记得多少?
【Redis】内存回收策略
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control
If someone asks you about distributed transactions again, throw this to him
[Brave food, not afraid of the linked list of brushing questions] Merging of ordered linked lists
LeetCode 86. 分隔链表
Analysis of the name matching process between the LCD driver and the device (Tiny4412)
怎么加入自媒体,了解这5种变现模式,让账号快速变现
皕杰报表在传参乱码
力扣练习——62 有效的数独
LCD驱动端与设备端名称匹配过程分析(Tiny4412)
实现内网穿透的最佳解决方案(无实名认证,完全免费)
LeetCode_152_乘积最大子数组
力扣练习——58 验证二叉搜索树
接口定义与实现
做自媒体月入几万?博主们都在用的几个自媒体工具
三个绘图工具类详解Paint(画笔)Canvas(画布)Path(路径)
不止跑路,拯救误操作rm -rf /*的小伙儿