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. python学习笔记02--列表和元组

    一.简介 数据结构是通过某种方式组织在一起的数据元素的集合. 序列是python中最基本的数据结构,python中包含6种内建的序列,分别是列表.元组.字符串.Unicode字符串.buffer对象和 ...

  2. Shell 文件测试运算符

    文件测试运算符 文件测试运算符用于检测 Unix 文件的各种属性. 属性检测描述如下: 操作符 说明 举例 -b file 检测文件是否是块设备文件,如果是,则返回 true. [ -b $file ...

  3. Maven之setting.xml配置文件详解

    setting.xml配置文件 maven的配置文件settings.xml存在于两个地方: 1.安装的地方:${M2_HOME}/conf/settings.xml 2.用户的目录:${user.h ...

  4. 性能监控(5)–JAVA下的jstat命令

    jstat的基本语法为 Usage: jstat -help|-options jstat -<option> [-t] [-h<lines>] <vmid> [& ...

  5. module.exports和exports.md

    推荐写法 具体解释可以往后看. 'use strict' let app = { // 注册全局对象 ... } ... // 封装工具箱 exports = module.exports = app ...

  6. LintCode Binary Search

    For a given sorted array (ascending order) and a target number, find the first index of this number ...

  7. 网页三剑客:HTML+CSS+JavaScript 之CSS概述

    CSS 简介 什么是 CSS? CSS 指层叠样式表 (Cascading Style Sheets) 样式定义如何显示 HTML 元素 样式通常存储在样式表中 把样式添加到 HTML 4.0 中,是 ...

  8. 【代码笔记】Web-ionic checkbox(复选框)

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  9. long数值 转换为时间

    项目中,服务器端经常给客户端开发人员传一个长整形的时间数据, 对于一个 长整形 1446801883000,可以明显的看出 是以毫秒为单位的,因为最后有三个零,如果没有连续3个零的话就要判断单位了 那 ...

  10. 使用windows命令和iconv.exe批量转换文件编码

    iconv是知名的开源跨平台编码转换库,iconv.exe是iconv库在windows下的命令行工具,iconv.exe的一般用法:iconv.exe -f gbk -t utf-8 gbk.txt ...