当前位置:网站首页>9. Delete nodes in the linked list
9. Delete nodes in the linked list
2022-07-28 10:16:00 【[email protected]】
- Input : head = [4,5,1,9], val = 5
Output : [4,1,9]
public ListNode deleteNode(ListNode head, int val) {
if(head.val == val) return head.next;// Determine whether the header node should be deleted
ListNode curr = head;
//curr.next As long as the value of is not equal to val, Just go straight down
while(curr.next != null && curr.next.val != val){
curr = curr.next;
}
//curr.next The value is equal to the val, Delete curr.next
if(curr.next != null) curr.next = curr.next.next;
return head;
}
- You can also consider using double pointers . If the code looks messy , Draw a picture , The idea soon came out .
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958224434.html
边栏推荐
猜你喜欢

15、判断二维数组中是否存在目标值

【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03

7、二分法——寻找一组重复或者有序但是旋转的数组

ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天

Thinking and summary of technical personnel | R & D Efficiency

Skillfully use NGX_ Lua makes traffic grouping

剑指offer

初识SuperMap iDesktop

MySQL架构原理
![[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
随机推荐
LSA and optimization of OSPF
什么样的知识付费系统功能,更有利于平台与讲师发展?
[cloud based co creation] Huawei cloud: metastudio digital content production line, which seamlessly integrates the virtual world with the real world
LIBCMTD.lib
MySQL的SQL TRACE一例
剑指offer
14、双指针——盛最多水的容器
Redis design specification
Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?
[esp32][esp idf] esp32s3 quickly build lvglv7.9
(1)机器学习概念总结
9、删除链表中节点
我用小程序容器让移动研发效率提升了5倍!
双指针技巧
centos7下安装mysql,网上文章都不太准
Go 内存模型 (2014年5月31日版本)
关于软考高级要不要报班学习
2. 输出数组中重复的数字之一
Kubernetes
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC