[leetcode 141] Linked List Cycle
2017-05-06 17:23
369 查看
我们可以.用两个指针:one slow and one fast来解决这个问题,slow走一步,fast走两步,slow与fast相遇的地方是slow第一次到达,fast第二次到达的地方
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def hasCycle(self, head): """ :type head: ListNode :rtype: bool """ slow=fast=head while fast and fast.next: slow=slow.next fast=fast.next.next if id(slow)==id(fast): return True return False
相关文章推荐
- LeetCode-Easy部分标签为LinkedList 141 Linked List Cycle
- leetcode 141:Linked List Cycle 问题与解答
- [Leetcode 141] Linked List Cycle
- Leetcode 141 Linked List Cycle
- leetcode_141题——Linked List Cycle (set)
- leetcode141: Linked List Cycle
- LeetCode: Linked List Cycle [141]
- 【LeetCode】141 - Linked List Cycle
- (LeetCode 141/142)Linked List Cycle
- leetcode 141-Linked List Cycle
- Leetcode 141 Linked List Cycle
- leetcode141~Linked List Cycle
- LeetCode 141 Linked List Cycle
- Leetcode 141 Linked List Cycle
- Leetcode[141]-Linked List Cycle
- LeetCode 141 Linked List Cycle(链表判环)
- [LeetCode]题解(python):141-Linked List Cycle
- 【leetcode】141/142Linked List Cycle(Floyd判圈算法)
- 【leetcode】【141】Linked List Cycle
- 【LEETCODE】141-Linked List Cycle