def hasCycle(head):
if not head:
return False
slow, fast = head, head
while slow and fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False