# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def hasCycle(self, head):
"""
:type head: ListNode
:rtype: bool
"""
prev_nodes = [head, ]
node = head
while node and node.next:
# print("hah", node.val)
node = node.next
if node in prev_nodes:
return True
prev_nodes.append(node)
return False