LeetCode 876. Middle of the Linked List(获得链表中心结点)
题意:获得链表中心结点。当有两个中心结点时,返回第二个。
分析:快慢指针。
/**
* 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(获得链表中心结点)的更多相关文章
- [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 ...
- 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. ...
- [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 ...
- 876. Middle of the Linked List - LeetCode
Question 876. Middle of the Linked List Solution 题目大意:求链表的中间节点 思路:构造两个节点,遍历链接,一个每次走一步,另一个每次走两步,一个遍历完 ...
- 【Leetcode_easy】876. Middle of the Linked List
problem 876. Middle of the Linked List 参考 1. Leetcode_easy_876. Middle of the Linked List; 完
- 【LeetCode】876. Middle of the Linked List 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用哑结点 不使用哑结点 日期 题目地址:https ...
- [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 ...
- 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 ...
- 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 ...
随机推荐
- 基于selenium+Python3.7+yaml+Robot Framework的UI自动化测试框架
前端自动化测试框架 项目说明 本框架是一套基于selenium+Python3.7+yaml+Robot Framework而设计的数据驱动UI自动化测试框架,Robot Framework 作为执行 ...
- 继承QWidget后无法使用QSS
使用继承QWidget后的类对象时,如果设置styleSheet看不到效果, 需要重写 void paintEvent(QPaintEvent *event); 方法, 在重写的方法中加入如下代码即可 ...
- STM32程序中 \r \n \r\n
1.用串口调试助手打印信息,程序换行时,最好还是用\r\n,光用\r或光用\n可能达不到换行的效果.
- mysql设置定时任务(对于中控心跳包的实现有意义)
转载:https://www.cnblogs.com/laowu-blog/p/5073665.html 目前用途:因为 脚本正常开关会给中控发送消息 但是万一脚本被强制关闭 没有触发脚本关闭事件就无 ...
- Mac安装php扩展redis遇到的问题,执行phpize问题
1.安装redis在mac OS中可以使用brew命令进行安装redis:mac OS使用brew命令安装软件安装命令:brew install redis因为我已经安装过了,这里就不在赘述.安装完之 ...
- netty(八)buffer源码学习3
问题 : compositeByteBuf 是干什么和其他 compositeByteBuf 有何区别 内部实现 概述 compositeByteBuf 就像数据库中的视图,把几个表的字段组合在一起, ...
- 安卓之滚动视图ScrollView
(1)垂直方向滚动时,layout_width要设置为match_parent,layout_height要设置为wrap_content (2)水平方向滚动时,layout_width要设置为wra ...
- CentOS7中JDK的安装和配置
1.使用yum线上安装jdk 这里以jdk1.7为例进行示范,1.8同理 yum -y list java* #浏览线上所有jdk版本列表,列表太长了,会显示不全 y ...
- IDEA部署项目,并结合Shell脚本运行Java程序
一.概述 在实际开发中,我们写好的代码,往往打成war包或jar包,通过winscp或其他软件将其上传至服务器,然而这样非常大的一个弊端就是不利于开发,为什么这么说呢?假如我们刚刚将springboo ...
- 2.1.FastDFS-单机拆分版-调度器安装配置
Centos610系列配置 我们在Centos610FastDFS单机模式-FastDFS安装 中已经完成了FastDFS的安装,接下来我们进行FastDFS调度器的安装. 1.找到FastDFS配置 ...