当前位置:网站首页>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];
}
}
边栏推荐
- Lex and yacc based lexical analyzer + parser
- Wireshark packet capturing TLS protocol bar displays version inconsistency
- Scala basic tutorial -- 12 -- Reading and writing data
- 力扣刷题日记/day2/2022.6.24
- Li Kou brush question diary /day7/6.30
- 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
- 基于lex和yacc的词法分析器+语法分析器
- 英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
- Scala基础教程--19--Actor
- Scala基础教程--12--读写数据
猜你喜欢

Scala基础教程--17--集合

Scala basic tutorial -- 20 -- akka

Process of manually encrypt the mass-producing firmware and programming ESP devices

中国农科院基因组所汪鸿儒课题组诚邀加入

Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
![[release] a tool for testing WebService and database connection - dbtest v1.0](/img/4e/4154fec22035725d6c7aecd3371b05.jpg)
[release] a tool for testing WebService and database connection - dbtest v1.0

An example of multi module collaboration based on NCF

力扣刷题日记/day6/6.28

My colleagues quietly told me that flying Book notification can still play like this

建立自己的网站(15)
随机推荐
2022 ByteDance daily practice experience (Tiktok)
力扣刷题日记/day3/2022.6.25
[cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
Lex and yacc based lexical analyzer + parser
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
千万不要只学 Oracle、MySQL!
An example of multi module collaboration based on NCF
Li Kou brush question diary /day3/2022.6.25
[release] a tool for testing WebService and database connection - dbtest v1.0
Go微服务(二)——Protobuf详细入门
Cache é JSON uses JSON adapters
字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验
SSL证书续费相关问题详解
What if the self incrementing ID of online MySQL is exhausted?
Technology sharing | interface testing value and system
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
Caché WebSocket
6.26CF模拟赛E:价格最大化题解
使用FTP
How is the entered query SQL statement executed?