当前位置:网站首页>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];
}
}
边栏推荐
- Pb extended DLL development (super chapter) (VII)
- 大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
- 2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import 'fmt' func
- 未来几年中,软件测试的几大趋势是什么?
- 2022 ByteDance daily practice experience (Tiktok)
- 发送和接收IBM WebSphere MQ消息
- Build your own website (15)
- 力扣刷题日记/day4/6.26
- 自由小兵儿
- What if the self incrementing ID of online MySQL is exhausted?
猜你喜欢

Mxnet implementation of googlenet (parallel connection network)

Principle and application of ThreadLocal

力扣刷题日记/day3/2022.6.25

Digital "new" operation and maintenance of energy industry

Don't just learn Oracle and MySQL!

How is the entered query SQL statement executed?

DeFi生态NFT流动性挖矿系统开发搭建

一种将Tree-LSTM的强化学习用于连接顺序选择的方法

基于lex和yacc的词法分析器+语法分析器

物联网应用技术的就业前景和现状
随机推荐
What types of Thawte wildcard SSL certificates provide
Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
How is the entered query SQL statement executed?
Torchdrug tutorial
File processing examples of fopen, FREAD, fwrite, fseek
未来几年中,软件测试的几大趋势是什么?
输入的查询SQL语句,是如何执行的?
【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
神经网络物联网是什么意思通俗的解释
sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
Scala基础教程--19--Actor
力扣刷题日记/day5/2022.6.27
DeFi生态NFT流动性挖矿系统开发搭建
Using FTP
How is the entered query SQL statement executed?
Scala basic tutorial -- 12 -- Reading and writing data
Cache é JSON uses JSON adapters
What if the self incrementing ID of online MySQL is exhausted?
2022养生展,健康展,北京大健康展,健康产业展11月举办