# 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. 【概率DP入门】

    http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710606.html 有关概率和期望问题的研究 摘要 在各类信息学竞赛中(尤其是ACM竞赛中) ...

  2. spark基本概念

    Client:客户端进程,负责提交作业到Master. Application:Spark Application的概念和Hadoop MapReduce中的类似,指的是用户编写的Spark应用程序, ...

  3. IE下图片切换的时候,图片总是切换不成功---根本问题是IE缓存图片

    作为WEB设计者,为了在网页展示上加强用户体验,经常会利用图象载入显示状态方法,这自然需要Image对象的onload事件. 在firefox浏览器下完成开发后,可是在IE浏览器中进行调试总不能被调用 ...

  4. SVN(一次检出&二次检出)

    一次检出: >进入经历文件夹 >输入svn checkout指令 >输入电脑密码 >输入用户名 >输入密码 >检出成功 第二次检出: >进入小涛文件夹 > ...

  5. char varchar varchar2 的区别 (转)

    char varchar varchar2 的区别       http://blog.csdn.net/honglei_zh/article/details/7172538区别:1.CHAR的长度是 ...

  6. Unix下C程序内存泄露检测工具:valgrind的安装使用

    Valgrind是一款用于内存调试.内存泄漏检测以及性能分析的软件开发工具. Valgrind的最初作者是Julian Seward,他于2006年由于在开发Valgrind上的工作获得了第二届Goo ...

  7. 关于 <video> 的兼容性测试

    测试浏览器 Firefox: 33.0.1 Chrome: 38.0.2125.111 m Safari: 5.1.7 IE: 9 和 10(6,7,8不考虑) 经测试:FF.Chrome.Safar ...

  8. mysqli扩展库的 预处理技术 mysqli stmt

    问题的提出? 现在需要向mysql数据库添加100个用户,请问如何实现? 思路: 使用for循环100次,向数据库中添加100个用户. 使用批量添加 $sql1=”insert xxx”; $ssql ...

  9. 嵌入式平台使用gtest进行白盒测试

    看了coderzh大神写的gtest(http://www.cnblogs.com/coderzh/archive/2009/04/06/1426755.html)使用的帖子,觉得gtest这个工具比 ...

  10. iOS中不透明度的查看

    模拟器工具条 Debug-->Color Blended Layers 即中文显示下 调试 -->颜色混合层 绿色代表不透明部分,红色代表透明部分,红色越多对性能影响越大