题目要求

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. dom4j string转为xml

    /**XML转字符串 */ Document document = new SAXReader().read(new File("E:test.xml"));;  String t ...

  2. <时间的玫瑰>读书笔记

    投资不需要高等数学,只需要常识和智慧 一个人在市场里的输赢结果,实际上是对他人性优劣的奖惩 投资像孤独的乌龟与时间竞赛 时间是最有价值的资产,我们今天买入的股票不仅仅属于我们自己,它属于整个家族,我们 ...

  3. java 中使用log4j

    一.控制台使用 1.导入log4j包到工程中 2.配置: log4j.rootLogger=DEBUG,console,R log4j.appender.console=org.apache.log4 ...

  4. rabbitmq启动异常table_attributes_mismatch

    rabbitmq启动异常table_attributes_mismatch 2017年01月09日 16:57:50 growithus 阅读数:18     [root@localhost rabb ...

  5. android 监听动画对象后不能播放动画

    采用监听  AnimationListener 发现不能播放动画了. 解决办法: 将动画的启动方式:animation.startnow去掉,改为如下即可 view.startAnimation(an ...

  6. Spark学习笔记——RDD编程

    1.RDD——弹性分布式数据集(Resilient Distributed Dataset) RDD是一个分布式的元素集合,在Spark中,对数据的操作就是创建RDD.转换已有的RDD和调用RDD操作 ...

  7. myeclipse创建hibernate工程

    1.创建数据库: from blog http://www.cnblogs.com/zhaocundang/p/9061959.html 使用navicat mysql IDE: 创建数据库 book ...

  8. tensflow自定义损失函数

    tensflow 不仅支持经典的损失函数,还可以优化任意的自定义损失函数. 预测商品销量时,如果预测值比真实销量大,商家损失的是生产商品的成本:如果预测值比真实值小,损失的则是商品的利润. 比如如果一 ...

  9. jxl和POI的区别

    最近两个项目中分别用到jxl和POI,因为用的都是其中的简单的功能,所以没有觉得这其中有太大的区别.有人针对他们做了比较,这里也拿出来展示一下. 首先从优缺点上来说 一.jxl 优点: Jxl对中文支 ...

  10. [Stats385] Lecture 04: Convnets from Probabilistic Perspective

    本篇围绕“深度渲染混合模型”展开. Lecture slices Lecture video Reading list A Probabilistic Framework for Deep Learn ...