题意:获得链表中心结点。当有两个中心结点时,返回第二个。

分析:快慢指针。

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* middleNode(ListNode* head) {
ListNode *fast = head;
ListNode *slow = head;
while(fast && fast -> next){
fast = fast -> next -> next;
slow = slow -> next;
}
return slow;
}
};

  

LeetCode 876. Middle of the Linked List(获得链表中心结点)的更多相关文章

  1. [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 ...

  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. ...

  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. 876. Middle of the Linked List - LeetCode

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

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

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

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

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

  7. [LeetCode&Python] Problem 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 ...

  8. 876. Middle of the Linked List

    1. 原始题目 Given a non-empty, singly linked list with head node head, return a middle node of linked li ...

  9. 876. Middle of the Linked List【Easy】【单链表中点】

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

随机推荐

  1. 谁说程序员没有时间关心女朋友的,Python 教你如何掌握女神情绪变化

    很多人都是在朋友圈装死,微博上蹦迪.微信朋友圈已经不是一个可以随意发表心情的地方了,微博才是! 所以你不要傻傻盯着女神的朋友圈发呆啦!本文教你如何用 Python 自动通知女神微博情绪变化,从今天开始 ...

  2. wordpress 支持上传中文名称文件

    添加文章难免要传个图.文件啥的,可是呢,上传中文名称的文件竟然不行,找了半天,中文乱码,脑残了,竟然忘了这个事,哎 修改其实很简单,只需要两步 1./wp-admin/includes/file.ph ...

  3. django模块导入/函数/中间件/MVC和MTV/CSRF

    目录 一:模块导入 二:函数 三:中间件 四:MVC和MTV 五:csrf 一:模块导入 第一种:继承 这里的母版更像是一个架子,子板都是定义的内容(如果多个页面中 ,存在相同的页面:这样我们可以抽到 ...

  4. Android学习06

    从开始学习Android,已经第5天,今天我换了一种方式,去观望了观望别人以及大佬的博客园,今天来做一下对比和反思,以便为后期的努力方向做好更充足的准备.在这里不得不佩服一下大佬们的学习能力和自我控制 ...

  5. Python socket day1

    客户端和服务端通过ip地址确认互相身份.(ip:用来在网络中标记一台电脑) 如果A,B两个人IP地址相同,接受到的信息有时候A收到,有时候B收到 当你用QQ时,双击选中头像其实就是选中了对方的IP地址 ...

  6. IIS 部署 web service

    1.在控制台检查 IIS 功能是否已经全部启用 2.重新注册IIS 3.设定程序池的正确版本

  7. python调用scala或java包

    项目中用到python操作hdfs的问题,一般都是使用python的hdfs包,然而这个包初始化起来太麻烦,需要: from pyspark impport SparkConf, SparkConte ...

  8. JavaScript的技巧45招

    JavaScript奇技淫巧45招 来自仲老师的分享: 原文地址[http://chensd.com/2015-01/45-useful-javascript-tips-tricks-and-best ...

  9. 吴裕雄--天生自然SSH框架开发:搭建一个完整的SSH框架

    下载jar包 spring框架的jar包:https://repo.spring.io/ hibernate框架的jar包:http://hibernate.org/orm/ struts2框架的ja ...

  10. js图片轮换播放器

    <!DOCTYPE html> <html> <head> <title></title> <meta charset="u ...