# 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 not head:
return False
if not head.next:
return False
turtle=head.next
rabbit=head.next.next
while turtle and rabbit:
if turtle == rabbit:
return True
turtle=turtle.next
if not rabbit.next:
return False
rabbit=rabbit.next.next
return False

@https://github.com/Linzertorte/LeetCode-in-Python/blob/master/LinkedListCycle.py

leetcode Linked List Cycle python的更多相关文章

  1. LeetCode Linked List Cycle II 和I 通用算法和优化算法

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

  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] Linked List Cycle 单链表中的环

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

  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. LEETCODE —— Linked List Cycle [Floyd's cycle-finding algorithm]

    Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it ...

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

  7. LeetCode: Linked List Cycle 解题报告

    Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it ...

  8. LeetCode Linked List Cycle 解答程序

    Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up: Can you solve i ...

  9. [Leetcode] Linked list cycle ii 判断链表是否有环

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

随机推荐

  1. 【Android】Intent中使用Extra传递数据

    传值方法一 Intent intent = new Intent(); Bundle bundle = new Bundle(); //该类用作携带数据 bundle.putString(" ...

  2. arm+linux 裸机环境搭建之安装工具篇(eclipse)

    之前已经讲述如何安装gcc和gdb,在此不赘述! 一.所需要的软件有两个: jre-7u25-linux-i586.rpm(虚拟机) eclipse-cpp-kepler-R-linux-gtk .t ...

  3. EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配

    C# mvc+EF 运行视图时出现问题:未能加载文件或程序集"EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToke ...

  4. JQ对JSON的增删改

    var userlist={ }, } } //方法一 userlist.row1.sex="女";//添加 userlist.row3={name:};//添加 userlist ...

  5. 新浪SAE数据库信息(用户&密码&主地址)

    用户名  : SAE_MYSQL_USER密 码 : SAE_MYSQL_PASS主库域名 : SAE_MYSQL_HOST_M从库域名 : SAE_MYSQL_HOST_S端 口 : SAE_MYS ...

  6. 在ie中用滤镜 (filter:progid:DXImageTransform.Microsoft.gradient)会触发overflow:hidden?

    1.在ie中用滤镜 (filter:progid:DXImageTransform.Microsoft.gradient)会触发overflow:hidden 在项目中做一个背景层透明内容(菜单)不透 ...

  7. 各种语言中的urlencode方法

    转载自:http://blog.sina.com.cn/s/blog_3f195d2501000a9b.html URLENCODE和URLDECODE是比较常用的URL参数转换方法,为以后使用方便, ...

  8. 00UILabel控件的详解

    文本属性 1.text:label显示的文字 2.font:text的字体,值不可以为nil,否则异常 3.textColor:text的颜色 4.textAlignment;text的对其方式 5. ...

  9. ASP 代码当前记录集不支持更新问题的解决办法。

    错误类型: ADODB.Recordset (0x800A0CB3) 当前记录集不支持更新.这可能是提供程序的限制,也可能是选定锁定类型的限制. /Model/manage/Admin_Admin.a ...

  10. web本地存储-IndexedDB

    IndexedDB, HTML5中的一种数据存储方式,索引数据库. 一个网站可能有一个或多个 IndexedDB 数据库,每个数据库必须具有惟一的名称.一个数据库可包含多个对象存储,一个对象存储相当于 ...