版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22795513/article/details/80663401
class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
if head == None:
return False
try:
p1 =head
p2 = head.next
except:
return False
while p1:
if p1 == p2:
return True
else:
try:
p1 =p1.next
p2 = p2.next
p2 = p2 .next
except:
return False
return False