Given an array nums of size n, return the majority element.
The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.
var majorityElement = function(nums) {
let map={};
let maxChar=nums[0];
for(let i=0;i<nums.length;++i){
const char=nums[i];
if(!map[char] || map[char]===0){
map[char]=1;
}else{
map[char]++;
}
if(map[char]>map[maxChar]){
maxChar=char;
}
}
return maxChar;
};