当前位置:网站首页>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];
}
}
边栏推荐
- 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
- 力扣刷题日记/day1/2022.6.23
- Halcon template matching
- Wireshark抓包TLS协议栏显示版本不一致问题
- Scala基础教程--17--集合
- MXNet对GoogLeNet的实现(并行连结网络)
- Li Kou brush question diary /day2/2022.6.24
- 模板_大整数减法_无论大小关系
- Rookie post station management system based on C language
- Scala基础教程--12--读写数据
猜你喜欢

An example of multi module collaboration based on NCF

Scala basic tutorial -- 13 -- advanced function
![[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation](/img/63/8d5f875b4409511628faf2914836d3.png)
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation

Uni app and uviewui realize the imitation of Xiaomi mall app (with source code)

Scala basic tutorial -- 20 -- akka

Mxnet implementation of googlenet (parallel connection network)

Li Kou brush question diary /day7/2022.6.29

Go microservice (II) - detailed introduction to protobuf

小发猫物联网平台搭建与应用模型

基于lex和yacc的词法分析器+语法分析器
随机推荐
6.26CF模拟赛B:数组缩减题解
Go microservice (II) - detailed introduction to protobuf
Interpretation of SIGMOD '22 hiengine paper
Scala基础教程--14--隐式转换
Using SSH
Nebula importer data import practice
From automation to digital twins, what can Tupo do?
Scala basic tutorial -- 18 -- set (2)
Li Kou brush question diary /day2/2022.6.24
What if the self incrementing ID of online MySQL is exhausted?
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
一、C语言入门基础
C language printing exercise
vbs或vbe如何修改图标
6.26CF模拟赛E:价格最大化题解
读写关闭的channel是啥后果?
[opencv introduction to mastery 9] opencv video capture, image and video conversion
李迟2022年6月工作生活总结
【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转
Scala基础教程--16--泛型