/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param gifts int整型一维数组
* @param n int整型
* @return int整型
*/
function getValue( gifts , n ) {
// write code here
let half = Math.ceil(n / 2);
let map = new Map();
for(let i = 0; i < n; i++) {
let gift = gifts[i];
if(map.has(gift)) map.set(gift, map.get(gift) + 1)
else map.set(gift, 1);
if(map.get(gift) >= half) return gift;
}
return 0;
}
module.exports = {
getValue : getValue
};