1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
var majorityElement = function(nums) { const [map, compare] = [new Map(), nums.length / 2];
for (const num of nums) { map.set(num, map.has(num) ? map.get(num) + 1 : 1); }
for (const [key, value] of map.entries()) { if (value > compare) { return key; } } };
|