#-*- coding: UTF-8 -*-
#Method:快慢指针法,建立虚表头,快指针走两步,慢指针走一步,若存在环,则快指针会追上慢指针
# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if head.next==None or head==None or head.next.next==None:
            return False
        dummy=listNode(0)
        dummy.next=head
        fast=dummy
        slow=dummy
        while pre!=None and cur!=None and cur.next!=None:
            
            slow=slow.next
            fast=fast.next.next
            if pre==cur:
                return True
        return False

【leetcode❤python】141. Linked List Cycle的更多相关文章

  1. 【LeetCode题解】链表Linked List

    1. 链表 数组是一种顺序表,index与value之间是一种顺序映射,以\(O(1)\)的复杂度访问数据元素.但是,若要在表的中间部分插入(或删除)某一个元素时,需要将后续的数据元素进行移动,复杂度 ...

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

  3. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

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

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

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

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

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

  7. 【leetcode❤python】 160. Intersection of Two Linked Lists

    #-*- coding: UTF-8 -*- #两种方法#方法1:#计算出A和B两个链表的长度分别为m.n;#长度长的链表先走m-n步,之后再一次遍历寻找#方法2:#先走到一个链表的尾部,从尾部开始走 ...

  8. 【leetcode❤python】 203. Remove Linked List Elements

    #-*- coding: UTF-8 -*- # Definition for singly-linked list.# class ListNode(object):#     def __init ...

  9. 【leetcode❤python】 234. Palindrome Linked List

    #-*- coding: UTF-8 -*-class Solution(object):    def isPalindrome(self, head):        ""&q ...

随机推荐

  1. 夺命雷公狗---Thinkphp----2之快快速搭建TP环境

    <?php //定义项目目录 define('APP_PATH','./WEB/'); //开启调试 define('APP_DEBUG',True); //包含thinkphp项目入口文件 r ...

  2. exe文件打开方式(恢复EXE文件关联)

    文件关联损坏常常是计算机病毒造成的,目前网络上有很多相关修复工具,相对来说,System Repair Engineer 支持的修复格式是比较齐全的,这个工具可以在http://www.kztechs ...

  3. 如何自动生成Facade 的EJB

    1.jbuilder中连接数据库,注意:java:/DataSource 2.选择数据表,右健选择"create cmp 2.x..." 3.添加"findAll&quo ...

  4. inupt textarea提示文字(点击消失,不输入恢复)

    <input name="textfield" type="text"  maxlength="20" value="请输入 ...

  5. 定义提示符 PS1 PS4

    PS1,如:[xiluhua@vm-xiluhua][~]$ # prompt PS1 export PATH BLUE=$(tput setaf ) PURPLE=$(tput setaf ) YE ...

  6. Cacti Install

    一.Cacti简介 Cacti是通过snmpget来获取数据,使用RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数.它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查 ...

  7. iOS身份证的正则验证

    在ios项目的开发中可能很多地方都需要用到身份证校验,一般在开发的时候很多人都是直接百度去网上荡相关的正则表达式和校验代码,但是网上疯狂粘贴复制的校验代码本身也可能并不准确,可能会有风险,比如2013 ...

  8. java 字符串处理

    第一张: 第二张:

  9. oracle VS postgresql系列-行列转换

    [需求]例如先有数据为 id | name ------+--------- | lottu | xuan | rax | ak | vincent 现在需要转换为 id | names ------ ...

  10. 流量分析 seo alexa 排名

    百度权重 举例,百度搜索中输入"中医百科" ,排名前三的: http://www.a-hospital.com/w/中医 1. url是关键词的方式,包含中文名,说明当前百度的搜索 ...