# 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. 纯CSS3编写的面包屑导航收集

    整理了10个纯CSS3制作的面包屑导航,这些都是通过CSS3来编写,十分方便,而且实用.有些文章附有教程,大家可以研究学习一下. 漂亮面包屑导航 查看网站 扁平化面包屑导航 查看网站 圆形风格面包屑导 ...

  2. SQL Server Reporting Services (SQLEXPRESS) 服务占用80端口

    win7, 好多时候,看到system进程占用了80端口,这个是系统进程,不能直接结束.我们不知道这个进程的哪个服务占用了80端口,这里记录其中一个服务"SQL Server Reporti ...

  3. C#中byte[] 与指针

    本文假定读者熟悉byte[].指针. C#是类型安全的,默认是不允许使用指针,但是针对C\C++或者其他语言的程序员(delphi)转为使用C#的的工作人员,不适用指针觉得很别扭.下面介绍一下基础的指 ...

  4. c# 自定义位数生成激活码

    Random random = new Random(~unchecked((int)DateTime.Now.Ticks));private string CreateAndCheckCode(Ra ...

  5. C# 2 闰年平年 老狼几点了

    作业 第一题 老狼几点了.凌晨,上午,下午,晚上. static void Main (string[] args) { //输入 Console.Write("老狼老狼几点了?" ...

  6. linux 日志查看总结

    1 grep "ERROR" catalina.log -a 20 -b 10 查看 catalina.log 中error的唯一 一行的后20行 前10行这种情况一般要唯一确定. ...

  7. poj 1450 Gridland

    Gridland Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. View的工作原理

    一.认识ViewRoot和DecorView 当Activity对象被创建的时候,会将DecorView添加到Window中,同时创建ViewRootImpl对象(ViewRoot对应于ViewRoo ...

  9. thinkphp批量删除的实现

    今天自己在写后台的时候需要把以前上传的测试文章全部删除掉,但是利用 [操作]里面的一个个删除比较慢,因此想出一个批量删除的解决方案. 首先在前端页面里面建立一个表单,这个表单是把你选中的单选按钮提交到 ...

  10. mysql性能优化学习笔记(1)优化目的、方向及数据库准备

    前言: 最近参加面试,问到了很多关于mysql的优化方面的问题,回答的不是很好,也是因为原先做的项目流量不是很大,所以对mysql优化不是太了解,所以趁着周末,恶补一下. 本文来源于慕课网sqlerc ...