当前位置:网站首页>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];
}
}
边栏推荐
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
- Digital "new" operation and maintenance of energy industry
- 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
- Torchdrug tutorial
- sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
- 问下各位大佬有用过cdc直接mysql to clickhouse的么
- One question per day (2022-07-02) - Minimum refueling times
- A method of using tree LSTM reinforcement learning for connection sequence selection
- 力扣刷题日记/day5/2022.6.27
- Li Kou brush question diary /day7/2022.6.29
猜你喜欢
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
How is the entered query SQL statement executed?
Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join
Torchdrug tutorial
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
2022年字节跳动日常实习面经(抖音)
[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
物联网应用技术的就业前景和现状
Basic tutorial of scala -- 16 -- generics
Principle and application of ThreadLocal
随机推荐
Scala basic tutorial -- 14 -- implicit conversion
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Caché JSON 使用JSON适配器
自由小兵儿
Scala basic tutorial -- 15 -- recursion
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
Scala basic tutorial -- 18 -- set (2)
李迟2022年6月工作生活总结
Scala基础教程--13--函数进阶
From automation to digital twins, what can Tupo do?
Go microservice (II) - detailed introduction to protobuf
性能优化之关键渲染路径
How is the entered query SQL statement executed?
Li Kou brush question diary /day7/6.30
力扣刷题日记/day2/2022.6.24
TorchDrug教程
redis分布式锁的8大坑总结梳理
Rookie post station management system based on C language
【机器学习的数学基础】(一)线性代数(Linear Algebra)(上+)
整理混乱的头文件,我用include what you use