当前位置:网站首页>Power button - 203 - remove the list elements linked list
Power button - 203 - remove the list elements linked list
2022-08-03 20:13:00 【Zhang Ran Ran √】
Title description
Give you the head node of the linked list head and an integer val, please delete all the nodes in the linked list that satisfy Node.val == val, and returns the new head node .
Solution ideas
- Because the element to be deleted may be at the head of the linked list, it is necessary to add a virtual node to the head in front of the head of the linked list
Input and output example


Code
/*** Definition for singly-linked list.* public class ListNode {* int val;*ListNode next;* ListNode() {}* ListNode(int val) { this.val = val; }* ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/class Solution {public ListNode removeElements(ListNode head, int val) {if(head == null){return head;}ListNode dummy = new ListNode(-1,head);ListNode pre = dummy;ListNode cur = head;while(cur != null){if(cur.val == val){pre.next = cur.next;}else{pre = cur;}cur = cur.next;}return dummy.next;}}边栏推荐
- Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
- 数学之美 第六章——信息的度量和作用
- matplotlib画polygon, circle
- 盲埋孔PCB叠孔设计的利与弊
- 信使mRNA甲基化偶联3-甲基胞嘧啶(m3C)|mRNA-m3C
- leetcode 231. 2 的幂
- In-depth understanding of JVM-memory structure
- LeetCode 1374. 生成每种字符都是奇数个的字符串
- Detailed AST abstract syntax tree
- php根据两点经纬度计算距离
猜你喜欢

Why BI software can't handle correlation analysis

消除对特权账户的依赖使用Kaniko构建镜像

(十六)51单片机——红外遥控

Lecture topics and guest blockbuster, TDengine developers conference to promote data technology "broken"

单调栈及其应用

从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么

abs()、fabs() 和 labs() 的区别

RNA-ATTO 390|RNA-ATTO 425|RNA-ATTO 465|RNA-ATTO 488|RNA-ATTO 495|RNA-ATTO 520近红外荧光染料标记核糖核酸RNA

力扣59-螺旋矩阵 II——边界判断
[email protected] 610/[email protected] 594/Alexa 56"/>染料修饰核酸RNA|[email protected] 610/[email protected] 594/Alexa 56
随机推荐
Pytorch GPU 训练环境搭建
后台图库上传功能
C51 存储类型与存储模式
Abs (), fabs () and LABS ()
abs()、fabs() 和 labs() 的区别
倒计时2天,“文化数字化战略新型基础设施暨文化艺术链生态建设发布会”启幕在即
Internet Download Manager简介及下载安装包,IDM序列号注册问题解决方法
Node version switching tool NVM and npm source manager nrm
glide set gif start stop
Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
1161 最大层内元素和——Leetcode天天刷【BFS】(2022.7.31)
Go语言类型与接口的关系
leetcode 剑指 Offer 15. 二进制中1的个数
2022 CCF中国开源大会会议通知(第三轮)
ES6 deconstruction assignment - array object deconstruction and deconstruction
嵌入式分享合集27
涨薪5K必学高并发核心编程,限流原理与实战,分布式计数器限流
机器学习中专业术语的个人理解与总结(纯小白)
The sword refers to Offer II 044. The maximum value of each level of the binary tree-dfs method
数学之美 第六章——信息的度量和作用