题目描述
blablabla
样例
blablabla
C++ 代码
class Solution {
public:
int duplicateInArray(vector<int>& nums) {
int slow = nums[0];
int fast = nums[nums[0]];
while(slow!=fast){
slow = nums[slow];
fast = nums[nums[fast]];
}
fast = 0;
while(slow!=fast){
slow=nums[slow];
fast = nums[fast];
}
return slow;
}
};