function fn(arr) {
let map = {}
for (let i of arr) {
map[i] = map[i] ? map[i] + 1 : 1;
}
for (let j in map) {
console.log(map[j])
if (map[j] > arr.length / 2) return j
}
return -1
}
let arr = [1,2,2,2,2,2,2,2,3,3,5,6]
console.log(fn(arr))
查找水王数
最新推荐文章于 2024-11-14 10:56:19 发布