当前位置:网站首页>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
边栏推荐
- B2B e-commerce website scheme for building materials industry: enable the transformation and upgrading of building materials enterprises to achieve cost reduction and efficiency improvement
- CloudCompare&PCL 匹配点采样一致性抑制
- Leetcode -- minimum number of rotation array
- 头文件库文件
- Etcd (highly available kV database)
- LandingSite电子标签Quuppa固件进入DFU状态说明
- leetcode——旋转数组的最小数字
- office2013以上输入数学公式
- LIBCMTD.lib
- Skillfully use NGX_ Lua makes traffic grouping
猜你喜欢
随机推荐
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
LIBCMTD.lib
小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?
ASP.NET Core 6框架揭秘实例演示[29]:搭建文件服务器
QT | some summaries of signals and slots
Leetcode076 -- the kth largest number in the array
Consul
JS promotion: the underlying principle of flat tiling
【云驻共创】华为云:MetaStudio数字内容生产线,让虚拟世界与现实世界无缝融合
️雄关漫道真如铁,而今迈步从头越️
基于ModelArts续写最伟大的作品【玩转华为云】
医药行业数字化建设,箭在弦上
_HUGE and __IMP__HUGE in “math.h“
21. 合并两个有序链表
It's settled! On July 30!
Double pointer technique
【JZOF】15二进制中1的位数
巧用ngx_lua做流量分组
排序——快速排序(快慢指针实现)





![[learning notes] border and period](/img/a4/5493f7eefc7dd0e38bc9a53a92b87b.png)


![[ESP32][esp-idf] AP+STA实现无线桥接 中转wifi信号](/img/bf/0a968064a8f7c11b86a2a2820208e6.png)
