题目描述
https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
参考
https://www.acwing.com/problem/content/video/14/
复杂度
时间:n
空间:1
代码
class Solution {
public:
int findRepeatNumber(vector<int>& nums) {
int val=-1;
int n=nums.size();
for(int i=0;i<n;i++){
val=nums[i];
while(val!=i){
if(val==nums[val]){
return val;
}
swap(nums[i],nums[val]);
val=nums[i];
}
}
return -1;
}
};
网友评论