题目要求

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. Selenium Web 自动化 - 如何找到元素

    Selenium Web 自动化 - 如何找到元素 2016-07-29 1. 什么是元素? 元素:http://www.w3school.com.cn/html/html_elements.asp ...

  2. Swing中支持自动换行的WrapLayout

    http://www.cnblogs.com/TLightSky/p/3482454.html ———————————————————————————————————————————————————— ...

  3. 【转】XML 特殊字符处理

    from: http://gdutlzh.blog.163.com/blog/static/164746951201222934328455/ 1. 在XML文件中,如果内容包含一些特殊字符会导致XM ...

  4. Numpy 定义矩阵的方法

    import numpy as np #https://www.cnblogs.com/xzcfightingup/p/7598293.html a = np.zeros((2,3),dtype=in ...

  5. Linux下MySQL5.7.18二进制包安装(无默认配置文件my_default.cnf)

    最新在学习MySQL,纯新手,对Linux了解的也不多,因为是下载的最新版的MySQL(MySQL5.7.18)二进制包,CentOS7.2下测试安装,方便以后折腾.大概步骤如下,安装删除反复折腾了几 ...

  6. 【Window 7】解决Win7远程桌面无法全屏的方法

    在Windows中有一项远程桌面功能,可以登录到其他电脑上进行远程控制,就像操纵本机一样,非常方便.但是最近发现用远程桌面登录过去时并不是全屏模式,而是窗口模式,老要拉滚动条,实在很不方便,今天还是到 ...

  7. [PHP] 01 - Hypertext Preprocessor

    超级文本预处理语言:http://php.net/ 集成的服务器组件,它已经包含了 PHP.Apache.Mysql 等服务 PHP 7 https://www.tutorialspoint. com ...

  8. ASP.NET MVC 4 (七) 模板帮助函数

    和普通HTML帮助函数不同,模板帮助函数不需要指定所用的HTML类型,MVC会推断选择合适的HTML元素,这让我们有更多的灵活性. 使用模板帮助函数 我们使用<ASP.NET MVC 4 (六) ...

  9. VNC实现Windows远程访问Ubuntu 16.04(无需安装第三方桌面,直接使用自带远程工具)

    本文主要是讲解如果理由VNC实现Windows远程访问Ubuntu 16.04,其实网上有很多类似教程,但是很多需要安装第三方桌面(xfce桌面等等),而且很多人不太喜欢安装第三方桌面,很多人像笔者一 ...

  10. Hadoop工作原理

    hadoop的核心思想是MapReduce,其处理数据的基本原理:在执行mapreduce之前,原始数据被分割成若干split,每个split作为一个map任务的输入,在map执行过程中split会被 ...