# 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. Java多线程并发编程之原子变量与非阻塞同步机制

    1.非阻塞算法 非阻塞算法属于并发算法,它们可以安全地派生它们的线程,不通过锁定派生,而是通过低级的原子性的硬件原生形式 -- 例如比较和交换.非阻塞算法的设计与实现极为困难,但是它们能够提供更好的吞 ...

  2. android 快速创建一个新的线程

    要给一个activity做成子线程的模式 第一种:直接创建子线程并启动 private Thread newThread; //声明一个子线程 new Thread() { @Override pub ...

  3. html5重力感应事件

    if (window.DeviceMotionEvent) { window.addEventListener('devicemotion',deviceMotionHandler, false); ...

  4. 从头开发MUDLIB

    跟Akuma一起从头打造mudlib--[第一讲] 第一讲:让它跑起来注:每一讲我都会上传一个相符的lib,有些文件是旧的,有些是新的,我尽可能在lib里写清楚注释.更详细的内容则在每讲的正文里写. ...

  5. PYthon成长之路第一篇(1)__字符串初识

    今天一起走进python的代码世界,一起领悟python的魅力 在很多学习python的书中都会以 print  “Hello,world!” 这样的而一个程序为开始,那么其中的 hello,worl ...

  6. C++ Primer第四版 15.9 再谈文本查询 程序实现

    编程过程中发现书本中的示例程序并不完全,某些地方存在错误,现已改正并添加少许注释.. 1 #include<iostream> 2 #include<fstream> #inc ...

  7. Prisma

    AI修图艺术:Prisma背后的奇妙算法 | 深度 投递人 itwriter 发布于 2016-07-30 12:47 评论(2) 有712人阅读 原文链接 [收藏] « » 雷锋网按:本文作者系图普 ...

  8. 查看Linux下网卡状态或 是否连接

    分类: 1) 通过mii-tool指令       [root@localhost root]# mii-tool        eth0: negotiated 100baseTx-FD, link ...

  9. NetworkManager——Linux强大的网络管理工具

    NetworkManager服务:NetworkManager - Linux Networking made Easy NetworkManager简介:NetworkManager由一个管理系统网 ...

  10. 在Linux下sqlplus 登录时显示SID 和用户名

    一般显示为: SQL> show user USER 为 "SYS" SQL> 在 $ORACLE_HOME/sqlplus/admin目录下 编辑glogin.sql ...