当前位置:网站首页>[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)
边栏推荐
- FLIR blackfly s industrial camera: explanation and configuration of color correction and code setting method
- First experience of JSON learning - the third-party jar package realizes bean, list and map to create JSON format
- How to use strings as speed templates- How to use String as Velocity Template?
- @Before, @after, @around, @afterreturning execution sequence
- Analyze "C language" [advanced] paid knowledge [II]
- Blue Bridge Cup 2022 13th provincial competition real topic - block painting
- 场景实践:基于函数计算快速搭建Wordpress博客系统
- 6 seconds to understand the book to the Kindle
- XML to map tool class xmlmaputils (tool class V)
- 2022/0524/bookstrap
猜你喜欢
刨析《C语言》【进阶】付费知识【一】
Recognition of C language array
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
BigDecimal 的正确使用方式
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
Livox激光雷达硬件时间同步---PPS方法
红外相机:巨哥红外MAG32产品介绍
Dall-E Mini的Mega版本模型发布,已开放下载
Basic introduction and use of dvajs
【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?
随机推荐
LeetCode. Sword finger offer 62 The last remaining number in the circle
Redis configuration class redisconfig
Modify the system time of Px4 flight control
JS Es5 can also create constants?
ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码
Livox激光雷达硬件时间同步---PPS方法
JS es5 peut également créer des constantes?
Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror
Flir Blackfly S工业相机:颜色校正讲解及配置与代码设置方法
ROS learning (24) plugin
CISP-PTE实操练习讲解(二)
场景实践:基于函数计算快速搭建Wordpress博客系统
ROS learning (23) action communication mechanism
Dall-E Mini的Mega版本模型发布,已开放下载
激光雷达:Ouster OS产品介绍及使用方法
ROS学习(24)plugin插件
解密函数计算异步任务能力之「任务的状态及生命周期管理」
Recognition of C language array
Make DIY welding smoke extractor with lighting