Description:
Given a linked list, determine if it has a cycle in it.
给定一个链表,确定出是否含有环
Solutions:
思路一:快指针和慢指针方法
class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
if head is None:
return False
fast=head
slow=head
while fast.next is not None and fast.next.next is not None:
slow=slow.next
fast=fast.next.next
if slow==fast:
return True
return False