输入:
[2, 3, 1, 0, 2, 5, 3]
输出:2 或 3
var findRepeatNumber = function(nums) {
const statistics = {};
for (let i=0; i<nums.length; i++) {
if (statistics[nums[i]]) {
return nums[i]
}
statistics[nums[i]] = 1;
}
};
var findRepeatNumber = function(nums) {
let mySet = new Set();
for (let i=0; i<nums.length; i++) {
if (mySet.has(nums[i])) {
return nums[i];
}
mySet.add(nums[i]);
}
};
var findRepeatNumber = function(nums) {
let arr = [];
for (let i=0; i<nums.length; i++) {
if (arr.includes(nums[i])) {
return nums[i];
}
arr.push(nums[i]);
}
};