当前位置:网站首页>Sword finger offer 18 Delete the node of the linked list
Sword finger offer 18 Delete the node of the linked list
2022-06-09 10:08:00 【Mr Gao】
The finger of the sword Offer 18. Delete the node of the linked list
Given the head pointer of one-way linked list and the value of a node to be deleted , Define a function to delete the node .
Return the head node of the deleted linked list .
Be careful : This question is different from the original one
Example 1:
Input : head = [4,5,1,9], val = 5
Output : [4,1,9]
explain : Given that the value of your list is 5 Second node of , So after calling your function , The list should be 4 -> 1 -> 9.
Example 2:
Input : head = [4,5,1,9], val = 1
Output : [4,5,9]
explain : Given that the value of your list is 1 The third node of , So after calling your function , The list should be 4 -> 5 -> 9.
This question is simple and conventional , The solution code is as follows :
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */
void f(struct ListNode* p,int val){
struct ListNode* pre;
pre=p;
p=p->next;
while(p){
if(p->val==val){
break;
}
pre=p;
p=p->next;
}
pre->next=p->next;
}
struct ListNode* deleteNode(struct ListNode* head, int val){
if(head==NULL) return head;
if(head->val==val){
return head->next;
}
f(head,val);
return head;
}
边栏推荐
- 华泰证券是安全的吗
- Composition of IT resources accessible anywhere, anytime
- 机器学习笔记 - 什么是BLEU分数?
- Introduction à l'AC du tissu, installation, utilisation
- MSF backdoor attack against FTP
- MSF SNMP based information collection
- [linear algebra] understand eigenvalues and eigenvectors
- 长安链ChainMaker多机环境
- 随时随地可访问的 IT 资源构成
- 978. 最长湍流子数组
猜你喜欢

Use a query statement to query the number of people whose data is within the score range of 0-60,60-80,80-100

【科技、商业和管理】看剧学创业:《硅谷》第六季第6-7集

Openstack explanation (13) -- Grace keystone setup and startup

Machine learning notes - breast cancer classification using keras and deep learning

MSF模块查找详解

【科技、商业和管理】看剧学创业:《硅谷》第六季第1-2集

Moral and regulatory knowledge of data science
![[technology, business and management] drama learning and Entrepreneurship: Silicon Valley season 5 Episode 4-6](/img/3b/32ef523daaa9a3d0a3805a6527c8e8.png)
[technology, business and management] drama learning and Entrepreneurship: Silicon Valley season 5 Episode 4-6

机器学习之房屋租赁价格预测:探索型数据分析+特征工程+建模+报告

Cve-2019-0192 Apache Solr remote deserialization Code Execution Vulnerability harm
随机推荐
Openstack explanation (12) -- glance installation and Preliminary Configuration
随时随地可访问的 IT 资源构成
【科技、商业和管理】看剧学创业:《硅谷》第六季第3-5集
[probability theory] correlation calculation between variables
1340. 跳跃游戏 V-动态规划加dfs
openstack详解(十七)——openstack Nova其他配置
MSF module search details
Machine learning notes - Introduction to R language learning series I
【genius_platform软件平台开发】第三十五讲:UDP进行跨网段广播
LeetCode_ Simulation_ Medium_ 621. task scheduler
- Bean method ‘redisConnectionFactory‘ in ‘JedisConnectionConfiguration‘ not loaded because @Conditi
循环神经网络理论——【torch学习笔记】
[technology, business and management] drama learning and Entrepreneurship: Silicon Valley season 5 Episode 4-6
JWT and session
机器学习笔记 - Transformer/Attention论文解读
Extensions attribute of TS generics
fabric-ca介绍,安装,使用
Openstack explanation (XX) -- neutron node principle
2220. 转换数字的最少位翻转次数
Openstack explanation (16) -- openstack Nova installation and database configuration