引用维基百科的定义:Floyd‘s cycle-finding algorithm is a pointer algorithm that uses only two pointers, which move through the sequence at different speeds. It is also called the "tortoise and the hare algorithm".
此算法主要应用于链表中,主要是判断链表是否有环以及环的起始位置。
这两个内容刚好对应于 LeetCode 的两道题,此随笔就以这两道题来讲解一下这个巧妙的算法。下面给出这两道题在 LeetCode 中的链接:
Floyd's cycle-finding algorithm
原文:https://www.cnblogs.com/AuKing/p/14037900.html