141.环形链表
看到题解贼搞笑一句话
史上最菜转圈圈
class Solution(object):
def hasCycle(self
, head
):
"""
:type head: ListNode
:rtype: bool
"""
slow
= fast
= head
if head
:
while fast
and fast
.next:
fast
= fast
.next.next
slow
= slow
.next
if fast
== slow
:
return True
return False
快慢指针一个快一个慢如果相遇,说明有圈圈
转载请注明原文地址: https://lol.8miu.com/read-15572.html