当前位置:网站首页>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];
}
}
边栏推荐
- How to download files using WGet and curl
- Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
- Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
- [release] a tool for testing WebService and database connection - dbtest v1.0
- One question per day (2022-07-02) - Minimum refueling times
- 技术分享 | 接口测试价值与体系
- Using FTP
- Microservice architecture debate between radical technologists vs Project conservatives
- Scala基础教程--19--Actor
- Nebula importer data import practice
猜你喜欢
MXNet对GoogLeNet的实现(并行连结网络)
1、 Introduction to C language
中国农科院基因组所汪鸿儒课题组诚邀加入
Don't just learn Oracle and MySQL!
力扣刷题日记/day2/2022.6.24
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
Scala基础教程--13--函数进阶
TorchDrug教程
Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
随机推荐
Li Kou brush question diary /day3/2022.6.25
Li Kou brush question diary /day1/2022.6.23
Li Kou brush question diary /day4/6.26
[cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
How to modify icons in VBS or VBE
模板_判断素数_开方 / 六素数法
Deleting nodes in binary search tree
2022养生展,健康展,北京大健康展,健康产业展11月举办
Is the securities account opened by qiniu safe?
6.26CF模拟赛B:数组缩减题解
Cache é JSON uses JSON adapters
Interpretation of SIGMOD '22 hiengine paper
Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
Torchdrug tutorial
Caché JSON 使用JSON适配器
IBM WebSphere MQ检索邮件
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
repeat_P1002 [NOIP2002 普及组] 过河卒_dp
Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
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