当前位置:网站首页>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
边栏推荐
- Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?
- LinkedList源码按摩,啊舒服
- 小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
- B2B2C系统亮点是什么?如何助力珠宝首饰企业打造全渠道多商户商城管理体系
- 2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
- 腾讯技术专家:解密亿级用户产品 微信、QQ、王者荣耀...全面上云实践!
- API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
- JS promotion: the underlying principle of flat tiling
- Etcd(高可用KV数据库)
- Sort - quick sort (fast and slow pointer Implementation)
猜你喜欢

【JZOF】14剪绳子

Flink - checkpoint Failure reason: Not all required tasks are currently running

Voice chat app - how to standardize the development process?

ES (8.1) certification topic
![[ESP32][esp-idf][LVGL7.9] 使用oled iic编译失败](/img/16/e5aa43df6ef9bdbc173fa547c85559.png)
[ESP32][esp-idf][LVGL7.9] 使用oled iic编译失败

The blind box of super primitive series will be launched soon, and platofarm will enable more rights and interests

Thinking and summary of technical personnel | R & D Efficiency

关于软考高级要不要报班学习
![[ESP32][esp-idf] esp32s3快速搭建LVGLV7.9](/img/39/8efef047d0a9223b97819a54b5edf8.png)
[ESP32][esp-idf] esp32s3快速搭建LVGLV7.9

房地产数字化转型方案:全方位数智化系统运营,助力房企管控实效提升
随机推荐
[jzof] 14 cut rope
【云驻共创】企业数字化转型,华为云咨询与你同行
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
(10) Defer keyword
[openharmony] [rk2206] build openharmony compiler (2)
图解 3 种主流企业架构模式(建议收藏!)
select如果不加order by子句,返回结果的顺序是不可靠的
Prometheus 运维工具 Promtool (四)TSDB 功能
OSPF的拓展配置,选路原则,防环及重发布
语音聊天app——如何规范开发流程?
Platofarm has made continuous progress, and has launched the official version and super primitive NFT successively
基于ModelArts续写最伟大的作品【玩转华为云】
MySQL架构原理
【云驻共创】华为云:MetaStudio数字内容生产线,让虚拟世界与现实世界无缝融合
Fixedwindowrollingpolicy introduction
并查集
OSPF expansion configuration, routing principles, anti ring and re release
头文件库文件
双指针技巧
二维前缀和