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 ...
随机推荐
- layuiAdmin pro v1.x 【单页版】开发者文档
layuiAdmin std v1.x [iframe版]开发者文档 题外 该文档适用于 layuiAdmin 专业版(单页面),阅读之前请务必确认是否与你使用的版本对应. 熟练掌握 layuiAdm ...
- docker删除mysql镜像失败Error response from daemon: conflict: unable to delete 8809d5286227 (must be forced) - image is being used by stopped container 1a2a427273b3
错误解析:这是由于要删除的目标镜像中有容器存在,故无法删除镜像 解决办法:先删除镜像中的容器,再删除该镜像.
- 松软科技课堂:JavaScriptDOM - 改变 CSS
HTML DOM 允许 JavaScript 更改 HTML 元素的样式. 改变 HTML 样式 如需更改 HTML 元素的样式,请使用此语法: document.getElementById(id) ...
- 避坑之Hadoop安装伪分布式(Hadoop3.2.0/Ubuntu14.04 64位)
一.安装JDK环境(这个可以网上随意搜一篇教程了照着弄,这里不赘述) 安装成功之后 输入 输入:java -version 显示如下说明jdk安装成功(我这里是安装JDK8) 二.安装Hadoop3. ...
- sqlserver查询使用with(nolock)详解
所有Select加 With (NoLock)解决阻塞死锁 在查询语句中使用 NOLOCK 和 READPAST 处理一个数据库死锁的异常时候,其中一个建议就是使用 NOLOCK 或者 READPAS ...
- 记一次深坑,dubbo暴露的服务无法注册到zookeeper的原因
项目用的架构,springboot,dubbo,zookeeper dubbo的provider作为服务单独使用,里面的service实现类使用了@Transactional注解,想集成spring的 ...
- Ora 命令行建立账号
.使用cmd 进入 sqlplus /nolog conn system/ as sysdba .修改密码 alter user ebthis identified by new_psw; .查看用户 ...
- 解决游览器安装Vue.js devtools插件无效的问题
一: 打开自己写的一个vue.js网页,发现这个图标并没有亮起来,还是灰色 解决方案: 1.我们先看看Vue.js devtools是否生效,打开Bilibili(https://www.bilib ...
- kongdashboard
apiVersion: v1kind: Servicemetadata: name: kong-dashboard namespace: kongspec: type: NodePort po ...
- Euler Sums系列(三)
\[\Large\sum_{n=1}^{\infty}\frac{\left(H_{n}^{(2)}\right)^{2}}{n^{2}}=\frac{19}{24}\zeta(6)+\zeta^{2 ...