题解 | #数组中出现次数超过一半的数字#
数组中出现次数超过一半的数字
https://www.nowcoder.com/practice/e8a1b01a2df14cb2b228b30ee6a92163
function MoreThanHalfNum_Solution(numbers) { // write code here const map = {} for (let i = 0; i < numbers.length; i++) { if (!map[numbers[i]]) { map[numbers[i]] = 1 } else { map[numbers[i]]++ } if (map[numbers[i]] >= Math.round(numbers.length / 2)) return numbers[i] } } module.exports = { MoreThanHalfNum_Solution : MoreThanHalfNum_Solution };