当前位置:网站首页>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;}}边栏推荐
- leetcode 剑指 Offer 58 - II. 左旋转字符串
- ES6-箭头函数
- 单调栈及其应用
- Lecture topics and guest blockbuster, TDengine developers conference to promote data technology "broken"
- Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
- 盲埋孔PCB叠孔设计的利与弊
- 云服务器如何安全使用本地的AD/LDAP?
- 8.2模拟赛总结
- tRNA甲基化偶联3-甲基胞嘧啶(m3C)|tRNA-m3C (3-methylcy- tidine)
- ESP8266-Arduino编程实例-BH1750FVI环境光传感器驱动
猜你喜欢

盲埋孔PCB叠孔设计的利与弊

使用 ReportLab 绘制 PDF

不知道这4种缓存模式,敢说懂缓存吗?

EasyCVR平台海康摄像头语音对讲功能配置的3个注意事项

Node version switching tool NVM and npm source manager nrm

转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G

Likou 59 - Spiral Matrix II - Boundary Judgment

Anaconda virtual environment migration

Abs (), fabs () and LABS ()
[email protected] 610/[email protected] 594/Alexa 56"/>染料修饰核酸RNA|[email protected] 610/[email protected] 594/Alexa 56
随机推荐
EasyCVR平台海康摄像头语音对讲功能配置的3个注意事项
【HiFlow】经常忘记签到怎么办?使用腾讯云场景连接器每天提醒你。
leetcode 448. Find All Numbers Disappeared in an Array 找到所有数组中消失的数字(简单)
Detailed steps for tensorflow-gpu2.4.1 installation and configuration
力扣707-设计链表——链表
演讲议题及嘉宾重磅揭晓,TDengine 开发者大会推动数据技术“破局”
matplotlib画polygon, circle
leetcode 剑指 Offer 15. 二进制中1的个数
危化企业双重预防机制数字化建设进入全面实施阶段
Detailed AST abstract syntax tree
ThreadLocal详解
微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东
Leetcode sword refers to Offer 15. 1 in the binary number
ES6 deconstruction assignment - array object deconstruction and deconstruction
化算力为战力:宁夏中卫的数字化转型启示录
头条服务端一面经典10道面试题解析
tRNA-m5C转运RNA(tRNA)修饰5-甲基胞嘧啶(m5C)|tRNA修饰m1Am2A (2-methyladenosine)
从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么
算法--交错字符串(Kotlin)
高并发,你真的理解透彻了吗?