当前位置:网站首页>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 (容斥原理)
- LCD驱动端与设备端名称匹配过程分析(Tiny4412)
- 苹果逆势扩大iPhone 14系列备货,总量或达9500万部
- LeetCode 237. 删除链表中的节点
- A case of violent parameter tuning in machine learning
- WeChat applet, global variables change in one place and the state in other places also changes.
- 配置druid数据源「建议收藏」
- POJ 2891 Strange Way to Express Integers (Extended Euclidean)
- A little self-deprecating deconstruction about farmers "code"
猜你喜欢
随机推荐
三个绘图工具类详解Paint(画笔)Canvas(画布)Path(路径)
What are some useful performance testing tools recommended? Performance testing report charging standards
MLX90640 红外热成像仪测温传感器 手机 APP 软件 RedEye 连接详细
LeetCode 92. 反转链表 II
【Redis】内存回收策略
LeetCode 237. 删除链表中的节点
HDU 4135: Co-prime (the principle of inclusion and exclusion)
英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
因为找不到lombok而找不到符号log
【机器学习】浅谈正规方程法&梯度下降
配置swagger
LeetCode_152_乘积最大子数组
LeetCode50天刷题计划(Day 17—— 下一个序列(14.50-16.30)
LeetCode50天刷题计划(Day 16—— 两两交换链表中的节点(9.10-10.30)
Where can I view the version record of WeChat applet submission review history?
LeetCode 19. 删除链表的倒数第 N 个结点
HDU 6040 Hints of sd0061 (技巧)
【LeetCode】640. 求解方程
A little self-deprecating deconstruction about farmers "code"
推荐6个自媒体领域,轻松易上手








