题目要求

Given a non-empty, singly linked list with head node head, return a middle node of linked list.

If there are two middle nodes, return the second middle node.

题目分析及思路

题目给出一个非空单链表,要求返回链表单的中间结点。可以将链表中的结点保存在list中,直接获取中间结点的索引即可。

python代码

# Definition for singly-linked list.

# class ListNode:

#     def __init__(self, x):

#         self.val = x

#         self.next = None

class Solution:

def middleNode(self, head: 'ListNode') -> 'ListNode':

l = [head]

while l[-1].next:

l.append(l[-1].next)

return l[len(l) // 2]

LeetCode 876 Middle of the Linked List 解题报告的更多相关文章

  1. 【LeetCode】876. Middle of the Linked List 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用哑结点 不使用哑结点 日期 题目地址:https ...

  2. [LeetCode] 876. Middle of the Linked List 链表的中间结点

    Given a non-empty, singly linked list with head node head, return a middle node of linked list. If t ...

  3. [LeetCode] 876. Middle of the Linked List_Easy tag: Linked List ** slow, fast pointers

    Given a non-empty, singly linked list with head node head, return a middle node of linked list. If t ...

  4. LeetCode 876. Middle of the Linked List(获得链表中心结点)

    题意:获得链表中心结点.当有两个中心结点时,返回第二个. 分析:快慢指针. /** * Definition for singly-linked list. * struct ListNode { * ...

  5. 【LeetCode】328. Odd Even Linked List 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  6. Leetcode:Flatten Binary Tree to Linked List 解题报告

    Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For ex ...

  7. 876. Middle of the Linked List - LeetCode

    Question 876. Middle of the Linked List Solution 题目大意:求链表的中间节点 思路:构造两个节点,遍历链接,一个每次走一步,另一个每次走两步,一个遍历完 ...

  8. [LeetCode] 160. Intersection of Two Linked Lists 解题思路

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  9. 【Leetcode_easy】876. Middle of the Linked List

    problem 876. Middle of the Linked List 参考 1. Leetcode_easy_876. Middle of the Linked List; 完

随机推荐

  1. Brainfuck解析器(Python)

    global cs global ip global ss #global sp global ds global bp global tab global out cs='++++++++++[&g ...

  2. Java知多少(70)面向字节流的应用

    文件输入输出流 文件输入输出流 FileInputStream 和 FileOutputStream 负责完成对本地磁盘文件的顺序输入输出操作. [例 10-5]通过程序创建一个文件,从键盘输入字符, ...

  3. Solr中的q与fq参数的区别

    转自:搜索系统5:Solr中的q与fq参数的区别在那儿 1.对结果排序有影响 今天遇到一个问题,把相同的参数比如name:张三,放到q与fq,两者返回的结果完全不一样. 经过debug发现,原因是这两 ...

  4. Weebly免费自助建站空间:可视化编辑网页搭建网站和绑定域名方法

    Weebly空间来自美国,已经稳定运行了有多年了,2007年被Time 评为50个最佳网站,属自助建站模式,功能强大.部落在09年时介绍了weebly.com自助建站服务,没有想到这多年来,Weebl ...

  5. LostRoutes项目日志——编辑project.json

    第一个Scene编译后运行会报错: Uncaught TypeError: Cannot read property 'style' of null 这是因为没有在project.json中包含已经编 ...

  6. 【BZOJ2671】Calc 数学

    [BZOJ2671]Calc Description 给出N,统计满足下面条件的数对(a,b)的个数: 1.1<=a<b<=N 2.a+b整除a*b Input 一行一个数N Out ...

  7. 用开源项目ActivityOptionsICS让ActivityOptions的动画实现兼容

    我之前写过一篇文章是讲解ActivityOption的api方法的(http://www.cnblogs.com/tianzhijiexian/p/4087917.html),当时吐槽各种动画不兼容, ...

  8. 关于ie6出现的问题的原因归结

    关于ie6出现的问题主要可以归结为以下几种情况把. 当然还存在各种原因,bug的情况也还有各种各样,我只是小结一下我自己经常遇到,比较有代表性的问题.会持续的更新. 1.浏览器本身存在的缺陷 比如: ...

  9. 慢慢看Spring源码

    1. 要想在java技术上提升一下,不看一下java源码是不行的,jdk源码,框架源码等.但是源码那么多,专门去看源码肯定很枯燥,所以就得一点一点看,坚持下去.有一点心得就记一点,如org.sprin ...

  10. hadoop Codec