# 141. Linked List Cycle

{% embed url="<https://leetcode.com/problems/linked-list-cycle/>" %}

在 Q202 里用过的龟兔赛跑`快慢指针`，相遇即证明有环。

{% content-ref url="202.-happy-number" %}
[202.-happy-number](https://xuqiangwen1994.gitbook.io/practice/202.-happy-number)
{% endcontent-ref %}

```python
class Solution:
    def hasCycle(self, head: ListNode) -> bool:
        if not head: return False
        slow = head
        fast = head.next
        
        while fast != slow:
            if not fast or not fast.next: return False
            else:
                fast = fast.next.next
                slow = slow.next
                
        return True
```
