代码思路:利用快慢指针遍历链表,若存在环形链表,两指针必相遇,否则快指针会先遍历完成
class Solution:
def hasCycle(self, head: ListNode) -> bool:
show=fast=head
while fast and fast.next:
show=show.next
fast=fast.next.next
if show==fast:
return True
return False
来源:CSDN
作者:jkn7
链接:https://blog.csdn.net/m0_37656366/article/details/104745759