当前位置:网站首页>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;}边栏推荐
- 越折腾越好用的 3 款开源 APP
- Not just running away, but saving the guy who mishandled rm -rf /*
- Analysis of the name matching process between the LCD driver and the device (Tiny4412)
- LeetCode 92. 反转链表 II
- 被面试官问到消息队列的丢失、重复与积压问题该如何回答
- The brave rice rice, does not fear the brush list of 】 list has a ring
- 2022年裁员潮,失业程序员何去何从?
- POJ 2891 Strange Way to Express Integers (Extended Euclidean)
- A little self-deprecating deconstruction about farmers "code"
- 做自媒体月入几万?博主们都在用的几个自媒体工具
猜你喜欢
随机推荐
常量及数据类型你还记得多少?
Stroke Practice - 62 Valid Sudokus
POJ 3101 Astronomy (Mathematics)
越折腾越好用的 3 款开源 APP
开源的作者,也有个生活问题
Licking Exercise - 60 Maximum key-value sum of binary search subtrees
实现内网穿透的最佳解决方案(无实名认证,完全免费)
力扣练习——62 有效的数独
Centos7 environment uses Mysql offline installation package to install Mysql5.7
LeetCode 369. Plus One Linked List(链表加1)
gpu-admission 源码分析
Redis常用命令
A case of violent parameter tuning in machine learning
OSSCore 开源解决方案介绍
Flutter气泡框实现
Introduction to Software Architecture
态路小课堂丨如何为CXP光模块选择光纤跳线?
关于振弦采集模块及采集仪振弦频率值准确率的问题
使用.NET简单实现一个Redis的高性能克隆版(六)
Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)








