1def hasCycle(head):2    fast, slow = head, head3    while fast and fast.next:4        fast = fast.next.next5        slow = slow.next6        if slow == fast:7            return True8    return False