# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None class Solution(object):
def detectCycle(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if not head:
return None
if not head.next:
return None
turtle=head.next
rabbit=head.next.next
while turtle and rabbit:
if turtle == rabbit:
p=head
while p != turtle:
p,turtle=p.next,turtle.next
return p
turtle=turtle.next
if not rabbit.next:
break
rabbit=rabbit.next.next
return None

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

leetcode Linked List Cycle II 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 解题报告

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

  3. [LeetCode] Linked List Cycle II 单链表中的环之二

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

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

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

  5. [LeetCode] Linked List Cycle II, Solution

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

  6. [LeetCode]Linked List Cycle II解法学习

    问题描述如下: Given a linked list, return the node where the cycle begins. If there is no cycle, return nu ...

  7. LeetCode——Linked List Cycle II

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

  8. Leetcode Linked List Cycle II

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

  9. [LeetCode] Linked List Cycle II 链表环起始位置

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

随机推荐

  1. 水平居中的两种方法margin text-align

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. eclipse自动提示类型的作用

    eclipse的自动提示功能确实十分好用,但是只是笼统的都勾上了,所有会有好多重复项,看着很眼疼. 今天就稍微研究了下,略微知道了几个类型的作用: 序号 类型 大体的中文意思 作用 1 Java Ty ...

  3. Apache Tiles 2.x 应用指南(转)

    转自:http://jaymsimusic.iteye.com/blog/1138906 Apache Tiles 2.x 应用指南 博客分类: Apache Tiles   Jakarta Tile ...

  4. zoj 1078

    非常简单的题,没什么好说的.唯一值得一提的就是在判断是否是回文的时候只需遍历一半的元素即可,稍微提高一点性能. #include<iostream> using namespace std ...

  5. CxImage整理(叠加字符/图像合并)

    //CxImage叠加字符 void CCxImageTestDlg::OnBnClickedButton1() { CxImage imgJPG; // 定义一个CxImage对象 imgJPG.L ...

  6. 饿了么 天降红包 bug ----这是谁的错

    早上来点餐,从没用饿了么点成功过,因为太难用. 今早,不,应该说前几天,出了个天降红包,领了个满20 减110的红包,没在意,因为还没升级客户端,不能用. 今早来,升级了一下客户端,下单了,看了饿了么 ...

  7. php curl封装类

    一个php curl封装的类,减少代码量,简化采集工作.这个类也是我工作的最常用的类之一.这里分享给大家.配合上phpquery,十分好用. <?php namespace iphp\core; ...

  8. Es分析

    http://my.oschina.net/lxbzj/blog/138587 http://donlianli.iteye.com/blog/1923017 http://tangzhaohui.n ...

  9. Windows 7安装教程(详细图解)

    早前向大家介绍了Windows XP的安装教程,今天思齐再来介绍一下Windows 7的安装教程,Windows 7在安装上相对以前的Windows操作系统都要简单一些,这一点对于尤其是非专业用户来说 ...

  10. 如何在Root的手机上开启ViewServer,使得HierachyViewer能够连接

    前期准备: 关于什么是Hierarchy Viewer,请查看官方文档:http://developer.android.com/tools/debugging/debugging-ui.html.个 ...