Pergunta de entrevista da empresa Amazon

How to check if there is a loop in a linked list

Resposta da entrevista

Sigiloso

25 de fev. de 2011

Use Floyd's cycle finding algorithm. Initialize two pointers, keep moving the first pointer in steps of 1 and the 2nd in steps of (say) 2; if they collide then you have a cycle

1