LC.P287[寻找重复数] 方法一:快慢指针123456789101112131415class Solution { public int findDuplicate(int[] nums) { int slow = nums[0], fast = nums[nums[0]]; while (slow != fast) { slow = nums[slow]; fast = nums[nums[fast]]; } slow = 0; while (slow != fast) { slow = nums[slow]; fast = nums[fast]; } return slow; }} 时间复杂度:$O(n)$ 空间复杂度:$O(1)$