0.code
class Solution {
public int findRepeatNumber(int[] nums) {
int len = nums.length;
for(int i=0;i<len;i++){
while(nums[i]!=i){
if(nums[i]==nums[nums[i]]){
return nums[i];
}
int temp = nums[i];
nums[i] = nums[nums[i]];
nums[temp] = temp;
}
}
return -1;
}
}
class Solution {
public int findRepeatNumber(int[] nums) {
int len = nums.length;
Set<Integer> set = new HashSet<>();
for(int i=0;i<len;i++){
if(!set.add(nums[i])){
return nums[i];
}
}
return -1;
}
}