class ListNode(object):
def __init__(self,x):
self.val = x
self.next = None
#判断是否有环函数Cycle
def Cycle(self,head):
if head==None:return False
fast=head
slow=head
while(fast):
if fast.next==None:
return False
fast=fast.next.next
slow=slow.next
if fast==slow:
return True
return False
利用Python实现环形列表代码
最新推荐文章于 2024-07-20 17:12:48 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)