# 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 appcompat备案

    使用Eclipse创建Android项目,project多出appcompat_v7,此情况在ADT升级到22.6.x版本后出现,22.3.x前版本不存在.此项为了实现向下兼容sdk的功能. 点击项目 ...

  2. mma ctf 1st && csaw 2015

    (很久以前做的,现在发一下)最近做了两个CTF,水平太渣,做了没几道题,挑几个自己做的记录一下. mma ctf 1st 之 rps: from socket import * s = socket( ...

  3. RCTF Re300 Writeup

    发现一篇写得更好的:http://insight-labs.org/?p=2009  程序要求输入一个flag.拿ida加载后,发现是Upx壳,脱壳后加载入ida进行分析.定位到输入flag的地方,如 ...

  4. ubuntu 开启 rewrite 模块

    1.sudo a2enmod rewrite 开启Rewrite模块 (停用模块,使用 a2dismod) 2. 在/etc/apache2/ 修改apache2.conf 文件中把AllowOver ...

  5. VB execl文件后台代码,基础语法

    Excel宏与VBA 程序设计实验指导1 实验1 Excel宏与VBA 语法基础 一.实验目的 1.熟练掌握录制宏.执行宏.加载宏的方法: 2.熟练使用Excel VBA编辑环境,掌握VBA的编辑工具 ...

  6. php将unicode编码转为utf-8方法

    介绍 在前端开发中,为了让中文在不同的环境下都能很好的显示,一般是将中文转化为unicode格式,即\u4f60,比如:"你好啊"的 unicode编码为"\u4f60\ ...

  7. 其实你不懂wget的心-01

    wget用英语定义就是the non-interactive network downloader,翻译过来就是非交互的网络下载器. 1 wget都支持什么协议的下载? wget支持HTTP.HTTP ...

  8. JS基础如何理解对象

    这几天跟几个同事聊天发现他们对javascript什么时候该用new都不是很了解. 1.javascript的function什么时候该new什么时候不该new?我觉得主要的问题还是集中在javasc ...

  9. redhat系列yum本地源配置

    1.挂载光盘,本示例挂载在/mnt下. 2.清除系统带的.repo文件,rm -f /etc/yum.repos.d/* 3.编辑自己的repo文件,内容如下: [local_server]   (库 ...

  10. 《UNIX网络编程》TCP客户端服务器例子

    最近在看<UNIX网络编程>(简称unp)和<Linux程序设计>,对于unp中第一个获取服务器时间的例子,实践起来总是有点头痛的,因为作者将声明全部包含在了unp.h里,导致 ...