[Leetcode]Linked List Cycle
来源:互联网 发布:mac 待机设置 编辑:程序博客网 时间:2024/05/05 21:30
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
比较常见的一道题 cracking code interview上也有~ 判断链表里有没有cycle 常见的方法是维护两个指针slow和fast,两个指针以不同的速度往前走,如果两个指针能相遇,则说明有cycle 这题不用判断cycle的起点,所以较容易
class Solution: # @param head, a ListNode # @return a boolean def hasCycle(self, head): if head is None: return False fast, slow = head, head while fast != None and fast.next != None: fast, slow = fast.next.next, slow.next if fast == slow: return True return False
0 0
- leetcode Linked List Cycle & Linked List Cycle ||
- 【LeetCode】Linked List Cycle
- Leetcode: Linked List Cycle
- Leetcode Linked List Cycle
- Leetcode: Linked List Cycle
- LeetCode:Linked List Cycle
- [LeetCode]Linked List Cycle
- LeetCode | Linked List Cycle
- Leetcode: Linked List Cycle
- LeetCode: Linked List Cycle
- LeetCode - Linked List Cycle
- [LeetCode] - Linked List Cycle
- LeetCode - Linked List Cycle
- [LeetCode]Linked List Cycle
- 【LeetCode】Linked List Cycle
- Linked List Cycle - LeetCode
- 【LeetCode】Linked List Cycle
- Linked List Cycle -- LeetCode
- Android Studio 1.0.1 + Genymotion安卓模拟器打造高效安卓开发环境
- Android高效加载大图、多图解决方案,有效避免程序OOM
- cloudera-manage 安装报错
- 用apache在本机配置多个基于ip的虚拟主机
- 『Gartner』2014 第三季手机销售统计
- [Leetcode]Linked List Cycle
- Android照片墙应用实现,再多的图片也不怕崩溃
- android判断应用是否有某个权限
- mac 终端 常用命令
- "linux ps -mH" 查看进程正在运行的线程
- 润乾集算报表提升性能之可控缓存
- Android 自定义控件——图片剪裁
- CocoaPods安装和使用教程
- 常用技巧(一) -- shell 赞