当前位置:网站首页>9、删除链表中节点
9、删除链表中节点
2022-07-28 09:58:00 【[email protected]】
- 输入: head = [4,5,1,9], val = 5
输出: [4,1,9]
public ListNode deleteNode(ListNode head, int val) {
if(head.val == val) return head.next;//判断头节点是否要删除
ListNode curr = head;
//curr.next的值只要不等于val,就一直往下走
while(curr.next != null && curr.next.val != val){
curr = curr.next;
}
//curr.next的值等于val,删除curr.next
if(curr.next != null) curr.next = curr.next.next;
return head;
}
- 也可以考虑使用双指针。如果代码看着乱,画个图,思路很快就出来了。
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zjj1910066023/article/details/124682764
边栏推荐
- Redis interview questions must be known and learned
- Flink - checkpoint Failure reason: Not all required tasks are currently running
- 【JZOF】15二进制中1的位数
- Status Notice ¶
- 剑指offer
- 小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
- select如果不加order by子句,返回结果的顺序是不可靠的
- Platofarm has made continuous progress, and has launched the official version and super primitive NFT successively
- Read Plato farm's eplato and the reason for its high premium
- 2022 uni app parsing token standard - use jsrsasign - climb the pit
猜你喜欢
![[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC](/img/16/e5aa43df6ef9bdbc173fa547c85559.png)
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC

软件设计师考前20问,注意啦!!

Installing MySQL for Linux operating system (centos7)

小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST

TCP Basics

2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了

Boss: there are too many systems in the company. Can we realize account interworking?

建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效

It's settled! On July 30!

Redis面试题必知必会
随机推荐
Cloudcompare & PCL matching point sampling consistency suppression
小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
2021-10-13arx
工业品MRO采购网站有哪些优势?一文带你读懂
CloudCompare&PCL 匹配点采样一致性抑制
1. 两数之和
头文件库文件
Kubernetes
博弈论 1.Introduction(组合游戏基本概念、对抗搜索、Bash游戏、Nim游戏)
二分、三分、01分数规划【第III弹】
ASP.NET Core 6框架揭秘实例演示[29]:搭建文件服务器
每天在岗不足8小时被辞?腾讯前员工追讨1300万加班费等,法院终审获赔9万
IE兼容性问题处理
leetcode076——数组中的第 k 大的数字
2021.07.13 我们是这样崩的
Sort - quick sort (fast and slow pointer Implementation)
OSPF的不规则区域,LSA和序列号
记录一次idea中的父子项目修改project与module名称,亲测!
MySQL架构原理
ES (8.1) certification topic