当前位置:网站首页>[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 .
边栏推荐
- R 语言nutrient数据集的可视化
- Scheduling with Testing
- Overview of common loss functions for in-depth learning: basic forms, principles and characteristics
- MySQL foundation - constraints
- 山东大学科技文献期末复习(个人速成向)
- 苹果GCD源代码
- 云服务器中安装mysql(2022版)
- 密码学系列之:PKI的证书格式表示X.509
- MySQL中如何计算同比和环比
- Remote access to raspberry pie via the Internet.
猜你喜欢

Moke 5. Service discovery -nacos

【奇葩需求之记录对象不同的日志】

【链表中倒数第k个结点】
![[proteus simulation] 74LS138 decoder water lamp](/img/30/7dbdead9c18788cd946b5541e76443.png)
[proteus simulation] 74LS138 decoder water lamp

uniapp小程序商城开发thinkphp6积分商城、团购、秒杀 封装APP

R 语言USArrests 数据集可视化

Software testing - Test Case Design & detailed explanation of test classification

MySQL foundation - constraints

软件测试——测试用例设计&测试分类详解

SwiftUI如何模拟视图发光增大的动画效果
随机推荐
Oracle system/用户被锁定的解决方法
Cryptography series: certificate format representation of PKI X.509
laravel+宝塔计划任务
Visualization of R language penguins dataset
Numpy learning notes (6) -- sum() function
80-分页查询,不止写法
扩展Ribbon支持基于元数据的版本管理
72-最近一次现场生产系统优化的成果与开发建议
Xunrui CMS custom data interface PHP executable code
百家讲坛 武则天
Gradle Build Cache引发的Task缓存编译问题
[observation] innovation in the software industry has entered a "new cycle". How can we make a new start in the changing situation?
超快变形金刚 | 用Res2Net思想和动态kernel-size再设计 ViT,超越MobileViT
Golang学习笔记—结构体
深度学习常用损失函数总览:基本形式、原理、特点
The real king of cache
Understand the index of like in MySQL
Kotlin1.6.20 new features context receivers tips
MySQL advanced (II)
78-生产系统不改代码解决SQL性能问题的几种方法