//双指针--快慢指针
class Solution {
public:
int duplicateInArray(vector<int>& nums) {
int slow=0,fast=0;
while(true){
slow=nums[slow];
fast=nums[nums[fast]];
if(slow==fast){
slow=0;
while(slow!=fast) slow=nums[slow],fast=nums[fast];
return slow;
}
}
return -1;
}
};