Below is the code after finding that loop exists in the list using Floyd's slow fast algorithm.
How can we be sure that begin and tortoise will meet at the beginning of the loop?
Node begin = head;
tortoise = tortoise.next;
while (begin != tortoise) {
begin = begin.next;
if (tortoise.next == begin) { // Find the position of the loop and mark the node as null
tortoise.next = null;
return;
}
tortoise = tortoise.next;
}
Any help would be appreciated!