def detect_cycle(head):
    """If head is a linked list with a cycle, its entry point node is returned. If not,
    None is returned.
    Time Complexity: O(N), where N is the number of nodes of the linked list.
    Space Complexity: O(1).
    :param head: ListNode
    :return: entry: ListNode
    """
    slow = head
    fast = head

    while fast and fast.next and fast.next.next:
        slow = slow.next
        fast = fast.next.next

        # If there is a cycle, at some point slow and fast should be equal.
        if slow == fast:

            # In that case, move head and slow until there are equal. That
            # node is the entry node.
            while slow != head:
                slow = slow.next
                head = head.next
            return slow

    return None