当前位置:网站首页>[876. intermediate node of linked list]
[876. intermediate node of linked list]
2022-06-22 21:05:00 【Cat star people who love Durian】
List of articles
One 、 Title Description
Given a header node as head The non empty single chain table of , Returns the middle node of the linked list .
If there are two intermediate nodes , Then return to the second intermediate node .
Example 1:
Input :[1,2,3,4,5]
Output : Nodes in this list 3 ( Serialization form :[3,4,5])
The returned node value is 3 . ( The evaluation system expresses the serialization of this node as follows [3,4,5]).
Be careful , We returned one ListNode Object of type ans, such :
ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, as well as ans.next.next.next = NULL.
Example 2:
Input :[1,2,3,4,5,6]
Output : Nodes in this list 4 ( Serialization form :[4,5,6])
Because the list has two intermediate nodes , Values, respectively 3 and 4, Let's go back to the second node .
Tips :
The number of nodes in a given list is between 1 and 100 Between .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/middle-of-the-linked-list
Two 、 Provide easy to read code diagram

3、 ... and 、 Title code
Ideas : Speed pointer
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */
struct ListNode* middleNode(struct ListNode* head){
struct ListNode*slow=head;
struct ListNode*first=head;
while(first&&first->next)
{
if(first->next)
{
slow=slow->next;
first=first->next->next;
}
}
return slow;
}
The above is the whole content of this article , If there are mistakes in the article or something you don't understand , Communicate more with meow bloggers . Learn from each other and make progress . If this article helps you , Can give meow bloggers a concern , Your support is my biggest motivation .
边栏推荐
- 72-最近一次现场生产系统优化的成果与开发建议
- Container container runtime (2): which is better for you, yum installation or binary installation?
- 百家讲坛 黄帝内经(第一部)
- PlainSelect.getGroupBy()Lnet/sf/jsqlparser/statement/select/GroupByElement;
- Remote access to raspberry pie via the Internet.
- MySQL foundation - constraints
- 91-oracle普通表改分区表的几种方法
- 70-根因分析-oracle数据库突发性能问题,谁来背这个锅
- 百家讲坛 大秦崛起(下部)
- 75-当left join遇到子查询
猜你喜欢

R语言 co2数据集 可视化

what? You can't be separated by wechat

讲真,Kotlin 协程的挂起没那么神秘(原理篇)

R语言penguins数据集可视化

CVPR 2022 oral | video text pre training new SOTA, HKU and Tencent arc lab launched excuse task based on multiple-choice questions

NumPy学习笔记(六)——sum()函数

One picture decoding opencloudos community open day

Easyclick fixed status log window

慕课6、实现负载均衡-Ribbon

【文末送书】火遍全网的AI给老照片上色,这里有一份详细教程!
随机推荐
79-不要看到有order by xxx desc就创建desc降序索引-文末有赠书福利
扩展Ribbon支持Nacos权重的三种方式
真正的缓存之王Caffine Cache
89-oracle SQL写法与优化器缺陷一例
How to calculate the Gini coefficient in R (with examples)
百家讲坛 武则天
Huawei cloud releases Latin American Internet strategy
74-这类SQL优化,oracle输给了mysql,如何补救?
【观察】软件行业创新进入“新周期”,如何在变局中开新局?
R 语言nutrient数据集的可视化
华为云发布拉美互联网战略
【138. 复制带随机指针的链表】
Notes d'apprentissage de golang - structure
Raspberry pie environment settings
It supports running in kubernetes, adds multiple connectors, and seatunnel version 2.1.2 is officially released!
采用网络远程访问树莓派。
Several common MySQL commands
迅睿CMS 自定义数据接口-php执行文件代码
R 语言 wine 数据集可视化
MySQL foundation - constraints