当前位置:网站首页>2095. delete the intermediate node of the linked list
2095. delete the intermediate node of the linked list
2022-06-11 08:55:00 【Drag is me】
leetcode Force button to brush questions and punch in
subject :2095. Delete the intermediate node of the linked list
describe : Give you a list of the head node head . Delete Linked list Intermediate nodes , And return the head node of the modified linked list head .
The length is n The middle node of the linked list is... From the beginning ⌊n / 2⌋ Nodes ( Subscript from 0 Start ), among ⌊x⌋ Is less than or equal to x Maximum integer for .
about n = 1、2、3、4 and 5 The situation of , The subscripts of the intermediate nodes are 0、1、1、2 and 2 .
Their thinking
1、 Double pointer ;
2、 Note the special case of only one node ;
Source code ##
class Solution {
public:
ListNode* deleteMiddle(ListNode* head) {
ListNode *slow = head, *fast = head;
if (fast->next == nullptr) return nullptr;
while (1) {
if (fast->next == nullptr) {
slow->val = slow->next->val;
slow->next = slow->next->next;
break;
} else if (fast->next != nullptr && fast->next->next == nullptr) {
slow->next = slow->next->next;
break;
}
fast = fast->next->next;
slow = slow->next;
}
return head;
}
};
边栏推荐
- EN 45545 R24氧指数测试方法解析
- Why is the string class final decorated
- 剑指 Offer 51. 数组中的逆序对
- leetcode - 739. Daily temperature
- (1) AAC opening - lifecycle, livedata, ViewModel and source code analysis skills of core component principles (Reprint)
- c的printf相关
- 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
- SQL基本查询
- PVC plastic sheets BS 476-6 determination of flame propagation properties
- K8S应用(四)—— 搭建redis5 集群(可供外部直接访问)
猜你喜欢

Sword finger offer 21 Adjust array order so that odd numbers precede even numbers

The interviewer asked four questions and summed up four experiences

Screening frog log file analyzer Chinese version installation tutorial

Matlab学习8-图像处理之线性与非线性锐化滤波、非线性平滑滤波

Award winning survey | how Apache pulsar lived in 2022, you the final say

TextView文本大小自动适配与TextView边距的去除

Not eligible for getting processed by all beanpostprocessors

ActiveMQ simple tutorial, suitable for beginners, learning notes yyds

The leader asked me to rewrite the test code. Should I do the same?

Create a nodejs based background service using express+mysql
随机推荐
206. 反转链表
win10家庭版如何连接远程桌面
马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup
【237. 删除链表中的节点】
20. 有效的括号
php 上传大文件 超过40秒 服务器500
Usage and difference between map and set in JS
Android 面试笔录(精心整理篇)
MySQL upgrade
How to apply for BS 476-7 sample for display? Is it the same as the display
[node] NPM part
PVC 塑料片BS 476-6 火焰传播性能测定
智能控制理论小题库
Complete ES6 questions
Sword finger offer 62 The last remaining number in the circle
86. 分隔链表
typescript高阶特性一 —— 合并类型(&)
File system check of the root filesystem failed
剑指 Offer 40. 最小的k个数
SQL basic query