当前位置:网站首页>[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)
边栏推荐
猜你喜欢

Schedulx v1.4.0 and SaaS versions are released, and you can experience the advanced functions of cost reduction and efficiency increase for free!

The cradle of eternity

张平安:加快云上数字创新,共建产业智慧生态

Flir Blackfly S 工业相机:通过外部触发实现多摄像头同步拍摄

Introduction to microservice architecture

STM32F4---通用定时器更新中断

处理streamlit库上传的图片文件

Livox激光雷达硬件时间同步---PPS方法

ROS学习(22)TF变换

Recognition of C language array
随机推荐
Modify the system time of Px4 flight control
JS how to quickly create an array with length n
初识MySQL
JVM 内存模型
BigDecimal 的正确使用方式
ROS learning (24) plugin
Stm32f4 --- general timer update interrupt
ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
RC振荡器和晶体振荡器简介
ROS学习(26)动态参数配置
Flir Blackfly S工业相机:颜色校正讲解及配置与代码设置方法
企业中台建设新路径——低代码平台
JS ES5也可以創建常量?
MySQL execution process and sequence
Redis configuration class redisconfig
MySQL最基本的SELECT(查询)语句
UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
Cisp-pte practice explanation (II)
一片叶子两三万?植物消费爆火背后的“阳谋”
张平安:加快云上数字创新,共建产业智慧生态