当前位置:网站首页>Sword finger offer 18 Delete the node of the linked list
Sword finger offer 18 Delete the node of the linked list
2022-06-11 08:55:00 【Drag is me】
leetcode Force button to brush questions and punch in
subject : The finger of the sword Offer 18. Delete the node of the linked list
describe : 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 .
Their thinking
1、 Because the deleted node happens to be the head node , So in advance head Add a node before ; So you just have to judge head->next Is it equal to val;
Source code ##
class Solution {
public:
ListNode* deleteNode(ListNode* head, int val) {
ListNode *start = new ListNode(-1);
ListNode *p = start;
start->next = head;
while (start) {
if (start->next->val == val) {
start->next = start->next->next;
break;
}
start = start->next;
}
return p->next;
}
};
边栏推荐
- 【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程
- SAP ABAP field symbol
- 2095. 删除链表的中间节点
- Matlab learning 8- linear and nonlinear sharpening filtering and nonlinear smoothing filtering of image processing
- Printf correlation of C
- CodeTop - 排序奇升偶降链表
- Sword finger offer 10- ii Frog jumping on steps
- Matlab r2022a installation tutorial
- What if the copied code format is confused?
- Interprocess communication
猜你喜欢

Redis6 entry-level tutorial. There are integration cases. You can directly see the integration cases. It is easy to get started

Screaming Frog Log File Analyser 中文版安装教程

Notes on MySQL core points

M1 芯片指南:M1、M1 Pro、M1 Max 和 M1 Ultra

Installation (detailed illustration) and use of SVN

Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup

Android interview transcript (carefully sorted out)

Textview text size auto fit and textview margin removal

【C语言-函数栈帧】从反汇编的角度,剖析函数调用全流程

使用express+mysql创建一个基于nodejs的后台服务
随机推荐
Matlab r2022a installation tutorial
Notes on MySQL core points
[node] NPM part
844. 比较含退格的字符串
Mazhiqiang: research progress and application of speech recognition technology -- RTC dev Meetup
leetcode - 460. LFU 缓存
Sword finger offer 40 Minimum number of K
SAP ABAP data types and data objects
EN 45545-2:2020 T11烟毒性检测
LiveData 与 StateFlow,我该用哪个?
M1 芯片指南:M1、M1 Pro、M1 Max 和 M1 Ultra
木板ISO 5660-1 热量释放速率摸底测试
EN45545-2 R26垂直燃烧测试介绍
For in / for of / foreach loop
显示屏DIN 4102-1 Class B1防火测试要求
面试题 02.02. 返回倒数第 k 个节点
leetcode - 460. LFU cache
Which Apple devices support this system update? See if your old apple device supports the latest system
Livedata and stateflow, which should I use?
剑指 Offer 51. 数组中的逆序对