当前位置:网站首页>876. 链表的中间结点
876. 链表的中间结点
2022-07-04 17:39:00 【charlsdm】
- 链表的中间结点
给定一个头结点为 head 的非空单链表,返回链表的中间结点。
如果有两个中间结点,则返回第二个中间结点。
示例 1:
输入:[1,2,3,4,5]
输出:此列表中的结点 3 (序列化形式:[3,4,5])
返回的结点值为 3 。 (测评系统对该结点序列化表述是 [3,4,5])。
注意,我们返回了一个 ListNode 类型的对象 ans,这样:
ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, 以及 ans.next.next.next = NULL.
示例 2:
输入:[1,2,3,4,5,6]
输出:此列表中的结点 4 (序列化形式:[4,5,6])
由于该列表有两个中间结点,值分别为 3 和 4,我们返回第二个结点。
提示:
给定链表的结点数介于 1 和 100 之间。
下面附上我的AC代码
public partial class Solution
{
public ListNode MiddleNode(ListNode head)
{
ListNode[] listNodes = new ListNode[100];
int index = 0;
while(head!=null)
{
listNodes[index] = head;
head = head.next;
index = index + 1;
}
return listNodes[(index)/2];
}
}
边栏推荐
- Mxnet implementation of googlenet (parallel connection network)
- A method of using tree LSTM reinforcement learning for connection sequence selection
- 工厂从自动化到数字孪生,图扑能干什么?
- 基于unity的愤怒的小鸟设计
- Scala基础教程--14--隐式转换
- [go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
- One question per day (2022-07-02) - Minimum refueling times
- 激进技术派 vs 项目保守派的微服务架构之争
- vbs或vbe如何修改图标
- 技术分享 | 接口测试价值与体系
猜你喜欢

Rookie post station management system based on C language

【uniapp】uniapp开发app在线预览pdf文件

Li Kou brush question diary /day4/6.26

Nebula importer data import practice

MXNet对GoogLeNet的实现(并行连结网络)

力扣刷题日记/day1/2022.6.23

Go微服务(二)——Protobuf详细入门

神经网络物联网应用技术学什么

Scala basic tutorial -- 13 -- advanced function

每日一题(2022-07-02)——最低加油次数
随机推荐
其他InterSystems %Net工具
中国农科院基因组所汪鸿儒课题组诚邀加入
MXNet对GoogLeNet的实现(并行连结网络)
C language printing exercise
神经网络物联网是什么意思通俗的解释
6.26CF模拟赛E:价格最大化题解
Li Kou brush question diary /day3/2022.6.25
[go ~ 0 to 1] read, write and create files on the sixth day
2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
力扣刷題日記/day6/6.28
Rookie post station management system based on C language
每日一题(2022-07-02)——最低加油次数
Caché WebSocket
整理混乱的头文件,我用include what you use
[opencv introduction to mastery 9] opencv video capture, image and video conversion
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Scala basic tutorial -- 17 -- Collection
Scala basic tutorial -- 13 -- advanced function
Scala basic tutorial -- 15 -- recursion
Mxnet implementation of googlenet (parallel connection network)