My solution:
Use map to traverse the array and return when the element has been saved in the map
class Solution {
public:
int findRepeatNumber(vector<int>& nums) {
map<int,int> m;
for(int i=0;i<nums.size();i++){
if(m.count(nums[i])) return nums[i];
m[nums[i]]=1;
}
return -1;
}
};