题目:

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的更多相关文章

  1. 【Lintcode】103.Linked List Cycle II

    题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...

  2. 【LeetCode】142. Linked List Cycle II

    Difficulty:medium  More:[目录]LeetCode Java实现 Description Given a linked list, return the node where t ...

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

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

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

  6. 【LeetCode】141. Linked List Cycle 解题报告(Java & Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 保存已经走过的路径 日期 [LeetCode ...

  7. 【LeetCode】142. Linked List Cycle II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 set 日期 题目地址:https://le ...

  8. 【easy】141. Linked List Cycle

    非常简单的题:判断链表有没有环(用快慢指针) /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...

  9. 【LeetCode】链表 linked list(共34题)

    [2]Add Two Numbers (2018年11月30日,第一次review,ko) 两个链表,代表两个整数的逆序,返回一个链表,代表两个整数相加和的逆序. Example: Input: ( ...

随机推荐

  1. 扩展MongoDB C# Driver的QueryBuilder

    扩展MongoDB C# Driver的QueryBuilder 因为不想直接hardcode "ClassA.MemberA.MemberB" 这种字符串 .写了下面几个类,用于 ...

  2. Window下安装Gradle并在IDEA中配置

    真是作死啊,Maven都只是用得半瓢水,还来搞Gradle,小心撩得一身骚啊. 下载Gradle 下载页面为:https://gradle.org/releases/ Gradle 4.1的下载地址: ...

  3. golang 内存池

    一般来说,内存池都是采用预分配的方式,分为固定大小的和非固定大小块,固定大小的内存效率高,非固定大小灵活.同时,分为单线程和多线程版的,单线程不需要考虑并发问题. 一般内存池的实现思想:分配一块比较大 ...

  4. POJ 3895 Cycles of Lanes (dfs)

    Description Each of the M lanes of the Park of Polytechnic University of Bucharest connects two of t ...

  5. Can a GridView have a footer and header just like ListView?

    Aquick question: In ListView I use this code: list.addHeaderView(headerView); How to deal with it wh ...

  6. [nio]dawn的基本概念

    1.dawn是单线程的: 为什么单线程?现实中非常多程序都是单线程的.比方redis,memcache,nodejs.mmorpgserver..... . 採用单线程有两大优点,首先,不须要使用锁, ...

  7. go test 下篇

    前言 go test 上篇 给大家介绍了golang自带的测试框架,包括单元测试和性能测试.但是在实际生产中测试经常会遇到一些网络或者依赖的第三方系统接口,运行测试用例的时候希望忽略这些接口的实际依赖 ...

  8. VC项目文件说明

    .dsp   项目参数配置文件,这个文件太重要,重点保护对象.. .dsw   工作区文件,重要性一般,因为它信息不我,容易恢复.   以下文件在项目中是可丢弃的,有些文件删除后,VC会自动生成的. ...

  9. 怎么利用jquery.form 提交form

    说明:开发环境 vs2012 asp.net mvc c# 利用jQuery.form.js提交form 1.HTML前端代码 <%@ Page Language="C#" ...

  10. iOS Dev (53) 修复UIImagePickerController偷换StatusBar颜色的问题

    版权声明:本文为 CSDN 博主 大锐哥(ID 为 prevention)原创文章,未经博主同意不得转载. https://blog.csdn.net/prevention/article/detai ...