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

分析:快慢指针。

/**
* 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. ssm框架整合,配置文件中的配置内容

    转自:https://www.cnblogs.com/dong-dong-1/p/8724127.html 使用idea工具开发,用maven进行管理. 最近在写毕业设计,因为对ssm框架一直半解,常 ...

  2. STA之OCV

    Timing sign-off Corner = library PVT +RC Corner + OCV 针对每个工艺结点,foundry都会给出一张类似的timing sign-off表格,定义了 ...

  3. vue 一些学习笔记

    var, let, const 区别 //-----------------var----------------- var a = []; for(var i= 0; i < 10; i++) ...

  4. 世界坐标转到UGUI坐标

    public static Vector3 WorldToUI(Camera camera,Vector3 pos){ CanvasScaler scaler = GameObject.Find(&q ...

  5. CentOS6.5_x64安装MySQL-5.6.17,在已经启动MySQL服务的情况下,出现密码报错ERROR 2002 (HY000)

    1.修改MySQL配置文件,使MySQL登陆时跳过密码验证 skip-grant-tables 2.重启MySQL服务 service mysql restart 3.进入MySQL,修改user表中 ...

  6. 去除移动端苹果手机(ios)的input默认样式与input禁止键盘出现的方式

    样式: input{-webkit-appearance: none;} 在iPhone plus点击input框出生日期时会出现如下图: 为了去掉下面那条苹果自带的,可以这样处理:在HTML中的in ...

  7. Java连载81-枚举类型,生成五个不重复的随机数,集合简介

    一.枚举类型 1.枚举类型的格式就是enum+枚举类型的名称,可见下面的例子. package com.bjpowernode.java_learning; ​ public class D81_1_ ...

  8. VBA 学习笔记 - 运算符

    学习资料:https://www.yiibai.com/vba/vba_operators.html 算术运算符 加减乘除模指,这个没啥特别的. 比较运算符 和 Lua 相比,判断相等变成了一个等于号 ...

  9. photoshop下载(ps)

    https://pan.baidu.com/s/1bNrUod2n1VqsA7Fr9RHtsg

  10. C:gcc的基本使用

    分布编译 预处理:gcc -E hello.c -o hello.i 编 译:gcc -S hello.i -o hello.s 汇 编:gcc -c hello.s -o hello.o 链 接:g ...