class Solution {
public:
bool hasCycle(ListNode *head) {
if (head == NULL) return NULL; //空表
ListNode *slow = head;
ListNode *fast = head;
while (fast&&fast->next){
slow = slow->next; fast = fast->next->next;
if (slow == fast)return true; //相遇
}
return false;
}
};

linked-list-cycle (快慢指针判断是否有环)的更多相关文章

  1. 142.Linked List Cycle II---双指针

    题目链接 题目大意:141题目的扩展,给出单链表,判断是否有环,如果有环,找出环的开始的结点,如果没有环,返回null. 法一(借鉴):在已经找出单链表环的基础上再找开始结点,要时刻记住这个环不一定是 ...

  2. [LeetCode] Linked List Cycle II 单链表中的环之二

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

  3. [LeetCode] 142. Linked List Cycle II 单链表中的环之二

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To r ...

  4. [算法][LeetCode]Linked List Cycle & Linked List Cycle II——单链表中的环

    题目要求 Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up: Can you so ...

  5. Linked List Cycle leetcode java (链表检测环)

    题目: Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without usin ...

  6. 【leetcode】Linked List Cycle II (middle)

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

  7. LeetCode: Linked List Cycle II 解题报告

    Linked List Cycle II Given a linked list, return the node where the cycle begins. If there is no cyc ...

  8. Linked List Cycle——LeetCode

    Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...

  9. 【一天一道LeetCode】#141. Linked List Cycle

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

随机推荐

  1. 分部类,分部方法 - 修饰符partial

    一.分部类 什么是部分类呢?简单来说就是将一个类型或方法拆分到两个或多个源文件中,每个源文件只包含类型定义的一部分. 当使用自动生成的源时,无须重新创建源文件便可将代码添加到类中.Visual Stu ...

  2. c# 正则格式化文本防止SQL注入

    /// <summary> /// 格式化文本(防止SQL注入) /// </summary> /// <param name="str">&l ...

  3. c# 键值数据保存XML文件

    /// <summary> /// 键值数据保存XML文件 /// </summary> /// <param name="fileName"> ...

  4. IEnumerable、ICollection、IList、List之间的区别与方法介绍

    区别 以下列出IEnumerable.ICollection.IList.List继承关系.(这里带有泛型,非泛型也是一样的关系) IEnumerable<T>: public inter ...

  5. hive命令的三种执行方式

    hive命令的3种调用方式 方式1:hive –f  /root/shell/hive-script.sql(适合多语句) hive-script.sql类似于script一样,直接写查询命令就行 不 ...

  6. 在C#中的构造函数和解析函数

    构造函数 class A() { A() {Console.write("构造函数");} } 当你在程序种出现 A a=new A();的时候 程序自动执行 构造函数 A() { ...

  7. 详解scss的继承、占位符和混合宏

    1.继承和占位符 两者都是通过@extend来引用. 1.1 继承 一个已经存在的css样式类,可以被其他样式类继承. 例如,实现以下css样式: .btn, .btn--primary, .btn- ...

  8. Android实现两次点击返回键提示退出

    Android的很多app中,都有点击一次返回键提示再次点击退出app的功能. 今天就看了下实现的方式,其实就是在相应的Activity中重写了onKeyDown()方法.在onKeyDown()方法 ...

  9. jquery之行自加自减

    实现目标:点击按钮复制本行,修改后重新插入到本行后面,点击复制出的行可删除本行 代码如下: <!DOCTYPE html> <html lang="en"> ...

  10. 为什么radio没有出现单选效果?

    原因是radio一定要设置相同的name,如下: <input type="radio" name="yunsuan" checked="che ...