leetcode -- Linked List Cycle -- 重点
来源:互联网 发布:mac os windows双系统 编辑:程序博客网 时间:2024/06/03 16:01
https://leetcode.com/problems/linked-list-cycle/
参考http://www.cnblogs.com/zuoyuan/p/3701639.html
一开始我错误的code:
class Solution(object): def hasCycle(self, head): """ :type head: ListNode :rtype: bool """ if not head : return False slow, fast = head, head while fast and fast.next and fast != slow:#这里这个条件fast!=slow,使得在一开始就无法进入循环 slow = slow.next fast = fast.next.next if fast == None or fast.next == None: return False else: return True
正确的code:
class Solution(object): def hasCycle(self, head): """ :type head: ListNode :rtype: bool """ if not head : return False slow, fast = head, head while fast.next and fast.next.next:#这里用fast and fast.next也可以 slow = slow.next fast = fast.next.next if slow == fast: return True return False
0 0
- leetcode -- Linked List Cycle -- 重点
- leetcode -- Linked List Cycle II -- 重点
- 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
- 关于U3D贴图格式压缩
- 1491: [NOI2007]社交网络
- 图片占用内存计算
- openwrt时间自动同步
- NuGet使用
- leetcode -- Linked List Cycle -- 重点
- [ahk]爬虫基础 post数据获取网站上的图片(获取艺术签名)
- fragment这个梗
- JavaScript的基本数据类型的父级
- 图形渲染优化、渲染管线优化、图形性能优化
- The import javax.servlet cannot be resolved解决办法
- 1001 害死人不偿命的(3n+1)猜想 PAT
- jquery文档操作函数大全
- 我的数学库