当前位置:网站首页>[leetcode] day97 remove linked list elements
[leetcode] day97 remove linked list elements
2022-07-07 02:08:00 【Upside down, it's a circle】
subject
203. Remove linked list elements 【 Simple 】
Answer key
Iterative solution
class Solution {
public ListNode removeElements(ListNode head, int val) {
ListNode newHead=new ListNode(0,head);
ListNode p=newHead;
while(p.next!=null){
if(p.next.val==val)
p.next=p.next.next;
else
p=p.next;
}
return newHead.next;
}
}
Time complexity : O ( n ) O(n) O(n)
Spatial complexity : O ( 1 ) O(1) O(1)
边栏推荐
- STM32F4---PWM输出
- STM32F4---通用定时器更新中断
- Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma
- FLIR blackfly s industrial camera: configure multiple cameras for synchronous shooting
- JS es5 peut également créer des constantes?
- 将截断字符串或二进制数据
- Flir Blackfly S 工业相机:通过外部触发实现多摄像头同步拍摄
- Public key \ private SSH avoid password login
- Blackfly s usb3 industrial camera: buffer processing
- SchedulX V1.4.0及SaaS版发布,免费体验降本增效高级功能!
猜你喜欢

AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
![Yiwen takes you into [memory leak]](/img/a8/bd1a57ef3bde8910eff2a5f68296df.png)
Yiwen takes you into [memory leak]

C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式

SchedulX V1.4.0及SaaS版发布,免费体验降本增效高级功能!

Flir Blackfly S USB3 工业相机:白平衡设置方法

激光雷达:Ouster OS产品介绍及使用方法

How can I code for 8 hours without getting tired.

FLIR blackfly s industrial camera: configure multiple cameras for synchronous shooting

Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins

微服务架构介绍
随机推荐
一文带你走进【内存泄漏】
刨析《C语言》【进阶】付费知识【二】
How can I code for 8 hours without getting tired.
[unique] what is the [chain storage structure]?
Blue Bridge Cup 2022 13th provincial competition real topic - block painting
ROS learning (XIX) robot slam function package cartographer
Modify the system time of Px4 flight control
猫猫回收站
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
JVM memory model
解密函数计算异步任务能力之「任务的状态及生命周期管理」
JS ES5也可以創建常量?
ROS学习(23)action通信机制
ROS学习(24)plugin插件
ROS learning (22) TF transformation
PartyDAO如何在1年内把一篇推文变成了2亿美金的产品DAO
Stm32f4 --- general timer update interrupt
When grep looks for a process, it ignores the grep process itself
First experience of JSON learning - the third-party jar package realizes bean, list and map to create JSON format
JS how to quickly create an array with length n