当前位置:网站首页>Likou Brush Question Record 6.1-----203. Remove linked list elements
Likou Brush Question Record 6.1-----203. Remove linked list elements
2022-08-09 02:06:00 【@ Bai Gui】
一、题目
二、代码
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
///统一链表格式
ListNode* dummyhead = new ListNode(0); //设置虚假的头结点 为了使得单节点和多节点情况统一
dummyhead->next = head;
//Define Action Nodes
ListNode* process_node = new ListNode(0);
process_node=dummyhead;
//定义临时节点
ListNode* temp_node = new ListNode(0);
while(process_node->next!=nullptr)
{
if(process_node->next->val==val) //If the next node value of the processing node is equal to val Then change the pointer directly
{
temp_node=process_node->next;
process_node->next=temp_node->next;
}
else
{
process_node=process_node->next;
}
}
std::cout<<"all is finish "<<std::endl;
delete temp_node;
// delete process_node; //和dummyhead指向同一片空间 所以删不掉
return dummyhead->next;
}
};
三、运行结果
边栏推荐
- Which is the best increased whole life insurance?Is it really safe?
- Z-Game on grid
- 谷歌翻译下载-免费谷歌翻译软件下载
- 电磁辐射安全标准及检测方法
- VOIP使用单端口替换动态端口池进行UDP通信
- MT4/MQL4 entry to proficient foreign exchange EA tutorial Lesson 1 Getting to know MetaEditor
- 力扣刷题记录6.1-----203. 移除链表元素
- JDBC技术(三)——使用Druid数据库连接池测试
- 力扣刷题记录3.1-----977. 有序数组的平方
- 力扣刷题记录--常用功能函数
猜你喜欢
随机推荐
Wireshark packet capture tool
gstreamer 记录
如何在推荐系统中玩转知识图谱
数据库设计的总结
Codeforces Round #809 (Div. 2)A~D1
字节输入流(InputStream)与字节输出流(OutputStream)
How SEMRush finds keywords for advertising
qps tps rps 区别
力扣刷题记录--常用功能函数
Use of torchversion.transforms
Latex example reference
最新豆瓣top250爬虫案例代码分析[注释齐全]
2022护眼产品展,北京眼健康展,眼科医学展,近视矫正设备展
Grid布局介绍
New Swagger3.0 tutorial, OAS3 quick configuration guide, to automate API interface documentation!
MT4/MQL4 entry to proficient foreign exchange EA tutorial Lesson 1 Getting to know MetaEditor
全文翻译:EDPB关于VVA(虚拟语音助理)中处理个人数据的指南02/2021
UsernameAuthenticationFilter授权成功后调用AuthenticationSuccessHandler时的解析
Go-9-数据类型-函数
MT4/MQL4入门到精通EA教程第一课-MQL语言常用函数(一)OrderSend()函数