tortoise
and hare
, to the head of the linked list.tortoise
one step and hare
two steps at a time until they either meet or hare
reaches the end of the list.hare
reaches the end (i.e., hare
or hare.next
is null
), return null
as there is no cycle.tortoise
and hare
meet, reset hare
to the head of the list.tortoise
and hare
one step at a time until they meet again.