当前位置:网站首页>876. 链表的中间结点
876. 链表的中间结点
2022-06-11 08:55:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:876. 链表的中间结点
描述:给定一个头结点为 head 的非空单链表,返回链表的中间结点。
如果有两个中间结点,则返回第二个中间结点。
解题思路
1、快慢指针;
2、数组,注意只有一个节点的特殊情况;
原代码##
class Solution {
public:
ListNode* middleNode(ListNode* head) {
ListNode *p = head;
int n = 0;
while (head) {
n++;
head = head->next;
}
if (n == 1) return p;
for (int i = 1; i < n / 2; ++i) {
p = p->next;
}
return p->next;
}
};
边栏推荐
- 命名实体识别之CRF的实现方式
- MATLAB R2022a 安装教程
- PHP uploading large files for more than 40 seconds server 500
- Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
- Introduction to knowledge atlas -- yedda annotation
- ActiveMQ simple tutorial, suitable for beginners, learning notes yyds
- PHP solves Chinese display garbled code
- MySQL advanced features, you can read more about it and meet the interview
- 使用express+mysql创建一个基于nodejs的后台服务
- Are the test methods of CMVSS TSD No. 302 and 49 CFR 571.302 the same
猜你喜欢

【clickhouse专栏】新建库角色用户初始化

What is the process of en 1101 flammability test for curtains?

Heap can also be regarded as a tree structure. It is specified that the root node must be greater than or less than the left and right child nodes, but the size order of the left and right child nodes

Matlab r2022a installation tutorial

MATLAB R2022a 安装教程

领导让我重写测试代码,我也要照办嘛?

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

What if the copied code format is confused?

剑指 Offer 21. 调整数组顺序使奇数位于偶数前面

ActiveMQ simple tutorial, suitable for beginners, learning notes yyds
随机推荐
光伏板怎么申请ASTM E108阻燃测试?
Redis6 entry-level tutorial. There are integration cases. You can directly see the integration cases. It is easy to get started
SQL基本查询
MySQL & Oracle database capacity query
EN 45545-2T10水平法烟密度检测的注意事项
Using docker compose to build redis5 cluster
室内膨胀型防火涂料根据BS 476-21 耐火标准测定需要符合几项?
AS 3744.1标准中提及ISO8191测试,两者测试一样吗?
木板ISO 5660-1 热量释放速率摸底测试
Analysis of EN 45545 R24 oxygen index test method
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
端口占用问题,10000端口
For in / for of / foreach loop
What is concurrent search set? Are you still worried about it? In fact, it is a problem of connected graph, which is not so difficult to understand
SAP abap 字段符号
leetcode - 460. LFU cache
Standardized compilation knowledge
2022 Niuke winter vacation 3
win10家庭版如何连接远程桌面
Cron expressions in scheduled tasks