# 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. css 元素居中方法

    目前知道有两种方法 方法一:主要适用于元素未设定高度的情况下. 直接上代码 html: <div class="nav-content"> <ul ng-clic ...

  2. 添加“返回顶部”小图标按钮的JS(JavaScript)代码详解

    如何给自己的网站添加方便快捷的"返回顶部"小图标按钮呢?如下图: JS源代码: /** * JavaScript脚本实现回到页面顶部示例 * @param acceleration ...

  3. 转:消除SDK更新时的“https://dl-ssl.google.com refused”错误

    消除SDK更新时,有可能会出现这样的错误: Download interrupted: hostname in certificate didn't match: <dl-ssl.google. ...

  4. Oracle GoldenGate配置异构数据库数据传输(oracle到sqlserer)的dml操作(带pump进程)

    实验环境:os01:Red Hat Enterprise Linux Server release 5.1 (32位)db01:oracle 10.2.0.1.0 os02:Windows 7 (32 ...

  5. How to Install/Deinstall Oracle Workspace Manager (文档 ID 263428.1)

    In this Document   Goal   Solution   References APPLIES TO: Workspace Manager - Version 9.0.1.0 to 1 ...

  6. 看懂此文,不再困惑于 JS 中的事件设计

    看懂此文,不再困惑于 JS 中的事件设计 今天刚在关注的微信公众号看到的文章,关于JS事件的,写的很详细也很容易理解,相关的知识点都有总结到,看完就有种很舒畅的感觉,该串起来的知识点都串起来了.反正一 ...

  7. [MFC]解决回车键 ESC 默认关闭窗口的一般方法

    在一般情况下编写的对话框程序,用户在运行的时候,如果不注意按下了ENTER或者ESC键,程序就会立刻退出,之所以会这样,是因为按下Enter键时,Windows就会自动去找输入焦点落在了哪一个按钮上, ...

  8. 在Google map图上做标记,并把标记相连接

    <!DOCTYPE html> <html> <head> <title>GeoLocation</title> <meta name ...

  9. windows下mysql数据库表名大小写不敏感

    最近新入职,领导让做个小功能先练练手.是一个添加分类的功能,有添加和列表,很简单.功能做完后提交,结果在线上出现一个大大的500. 但是我再本地环境下是正常的,我以为可能是php的版本不一致导致的问题 ...

  10. phpcms在自定义模块中的自定义标签分页

    如果你是一个经验丰富的phpcms二次开发人员,本篇文章可以忽略不计,因为这里的写法自己都觉得很恶心        今天在开发一个网站自建了一个模块叫做论坛模块,目录名称:luntan        ...