class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
if head == None or head.next == None:
return False
fast = slow = head
while head and head.next:
slow = slow.next
fast = fast.next.next
if fast == slow:
return True
return False
在判断非空的时候 报错
但是又可以跑得通
AttributeError: 'NoneType' object has no attribute 'next'
fast = fast.next.next
讲while head and head.next:改成while fast and fast.next:
就可以submit了 这是为什么 求解答