# 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. 实用的JavaScript技巧、窍门和最佳实践

    JavaScript是世界上第一的编程语言,它是Web的语言,是移动混合应用(mobile hybrid apps)的语言(比如 PhoneGap或者 Appcelerator),是服务器端的语言(比 ...

  2. oracle后台进程2

    oracle中的进程共分为三类:用户进程.服务进程.后台进程.其中后台进程伴随实例的启动而启动,他们主要是维护数据库的稳定,相当于一个企业中的管理者及内部服务人员.他们并不会直接给用户提供服务. 一: ...

  3. 【单调队列】【3-21个人赛】【problmeB】

    Problem B Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  4. CXF interceptor拦截顺序

    CXF Interceptor中Phase的先后顺序 org.apache.cxf.phase.PhaseManagerImpl中 final void createInPhases() { int  ...

  5. (七)Android中AIDL的应用与理解

    一.跨应用启动Service Intent serviceIntent=new Intent();serviceIntent.setComponent(new ComponentName(" ...

  6. NSString 遍历

    遍历NSString网上大多数有两种方法 最简单有效的是: NSString *name=[[NSString alloc] initWithFormat:@"小猫咪爱上大老鼠!!" ...

  7. log4net自定义扩展及配置说明

    log4net文件保存配置我就不说太多了,网上一大把的,数据库配置其实网上也有,只是我第一次按照网上的配置没有跑通,我就说下数据库配置需要注意的地方吧. 下面是一个log4net的数据库代码配置 pu ...

  8. delete 指针

    #include<iostream>using namespace std;class human{public: human(){cout<<"构造";} ...

  9. J2SE知识点摘记(二)

    1.    对象的声明 "类名 对象名 = new 类名();"例子:Person P;//先声明一个Person类的对象p p=new Person();//用new关键字实例化 ...

  10. Balsamiq Mockups registration code

    最近使用Mockups 进行页面原型设计,发现是未注册的,于是网上查询了下注册码,居然有效,在此记录下.    有需要的朋友也可以试试. Name:Rick Dong     Key:eNrzzU/O ...