下面是一个问题:
Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.
只剩下一只南数,这又是重复的。
You must solve the problem without modifying the array nums and uses only constant extra space.
制约因素:
- 1 <= n <= 10^5
- nums.length == n + 1
- 1 <= nums[i] <= n
- All the integers in nums appear only once except for precisely one integer which appears two or more times.
实例:
- Input: nums = [1,3,4,2,2]
- Output: 2
在审议了这个问题之后,我想到了一个周期,但我确信,这必然会形成一个周期。
在阅读解决办法后,我发现Flinoyd的周期调查算法可以在此适用。
然而,我只是在寻找相关名单的周期时使用这一算法。 回答只是告诉我,我可以通过这样做来取得结果,但它却告诉我,我为什么可以这样做。 我总是对这个阵列如何能够“变成与圈相连接的一个名单”感到迷惑。 谁能帮助我证明这一点?