数组中的重复的数字
C++代码class Solution {
public:
int findRepeatNumber(vector& nums){
set numsSet;
for(int i = 0; i < nums.size(); i++){
if(numsSet.find(nums[i]) == numsSet.end()){
numsSet.insert(nums[i]);
}
else{
return nums[i];
}
}
return -1;
}
};
Java代码
class Solution {
public int findRepeatNumber(int[] nums) {
Set set = new HashSet();
int repeat = -1;
for (int num : nums) {
if (!set.add(num)) {
repeat = num;
break;
}
}
return repeat;
}
}
如果有任何问题可以邮箱联系我:raymondlam1@yeah.net



