题解 | #数组中出现次数超过一半的数字#
数组中出现次数超过一半的数字
https://www.nowcoder.com/practice/e8a1b01a2df14cb2b228b30ee6a92163
function MoreThanHalfNum_Solution(numbers) { // write code here let result=numbers.reduce((temp,data)=>{ temp[data]=temp[data]?temp[data]+1:1; return temp; },{}) let num; for(let index in result){ if(result[index]>numbers.length/2){ num=index; } } return num; } module.exports = { MoreThanHalfNum_Solution : MoreThanHalfNum_Solution };
reduce函数累加