class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
ans=[]
while head:
if head in ans:
return True
ans.append(head)
head=head.next
return False