【Lintcode】102.Linked List Cycle
题目:
Given a linked list, determine if it has a cycle in it.
Example
Given -21->10->4->5, tail connects to node index 1, return true
题解:
Solution 1 ()
class Solution {
public:
bool hasCycle(ListNode *head) {
if (!head) {
return false;
}
ListNode* fast = head;
ListNode* slow = head;
while (fast && fast->next) {
slow = slow->next;
fast = fast->next->next;
if (slow == fast) {
return true;
}
}
return false;
}
};
【Lintcode】102.Linked List Cycle的更多相关文章
- 【Lintcode】103.Linked List Cycle II
题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...
- 【LeetCode】142. Linked List Cycle II
Difficulty:medium More:[目录]LeetCode Java实现 Description Given a linked list, return the node where t ...
- 【LeetCode】141. Linked List Cycle (2 solutions)
Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it ...
- 【LeetCode】142. Linked List Cycle II (2 solutions)
Linked List Cycle II Given a linked list, return the node where the cycle begins. If there is no cyc ...
- 【LeetCode】141. Linked List Cycle
题目: Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ...
- 【LeetCode】141. Linked List Cycle 解题报告(Java & Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 保存已经走过的路径 日期 [LeetCode ...
- 【LeetCode】142. Linked List Cycle II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 set 日期 题目地址:https://le ...
- 【easy】141. Linked List Cycle
非常简单的题:判断链表有没有环(用快慢指针) /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...
- 【LeetCode】链表 linked list(共34题)
[2]Add Two Numbers (2018年11月30日,第一次review,ko) 两个链表,代表两个整数的逆序,返回一个链表,代表两个整数相加和的逆序. Example: Input: ( ...
随机推荐
- cocos2d-x-3.1 国际化strings.xml解决乱码问题 (coco2d-x 学习笔记四)
今天写程序的时候发现输出文字乱码,尽管在实际开发中把字符串写在代码里是不好的做法.可是有时候也是为了方便,遇到此问题第一时间在脑子里面联想到android下的strings.xml来做国际化.本文就仅 ...
- SpringMvc自动代理
自动配置的好处是不需要挨个 实现[org.springframework.aop.framework.ProxyFactoryBean] ,只需要 advisor 配置和 <bean id=&q ...
- java 获取微信 页面授权 获取用户openid
先调用微信的地址 跳转https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4b4009c4fce00e0c&redirect ...
- Spring、Hibernate 数据不能插入到数据库问题解决
1.问题:在使用Spring.Hibernate开发的数据库应用中,发现不管如何,数据都插不到数据库. 可是程序不报错.能查询到,也能插入. 2.分析:Hibernate设置了自己主动提交仍然无论用, ...
- python 基础 7.6 sys 模块
一.sys 模块 sys 模块主要功能是获取参数 [root@www pythonscripts]# cat 2.py #!/usr/bin/python #coding=utf-8 im ...
- 【BZOJ1969】[Ahoi2005]LANE 航线规划 离线+树链剖分+线段树
[BZOJ1969][Ahoi2005]LANE 航线规划 Description 对Samuel星球的探险已经取得了非常巨大的成就,于是科学家们将目光投向了Samuel星球所在的星系——一个巨大的由 ...
- javascript实现日期时间动态显示
.aspx代码例如以下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Def ...
- STO存在哪些潜在隐患?
STO(Security Token Offering),即证券型通证发行,无疑是现目前区块链圈子讨论最热门的话题之一,纵使STO有很好的前景,但是其潜在隐患也不得不引起重视. 第一,STO与分布式网 ...
- SQL 中GROUP BY 、ROLLUP、CUBE 关系和区别
转自:http://www.cnblogs.com/dyufei/archive/2009/11/12/2573974.html 不言自明,看SQL就完全理解了,不需要过多解释,不错,分享之: ROL ...
- Java for LeetCode 087 Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...