# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def hasCycle(self, head: ListNode) -> bool:
pre=head
if head==None or head.next==None:
return False
l1=head
l2=head.next
while (l1!=l2):
if l2==None or l2.next==None:
return False
else:
l1=l1.next
l2=l2.next.next
return True
力扣第九天——环形链表
最新推荐文章于 2024-04-22 19:56:47 发布