class Solution:
def hasCycle(self, head: ListNode) -> bool:
fast,slow=head,head
while fast and fast.next: #以快指针为循环结束条件,则比较方便
fast=fast.next.next
slow=slow.next
if fast==slow:
return True
return False
环形链表
最新推荐文章于 2024-05-22 15:57:05 发布