题目:
class Solution {
public:
int majorityElement(vector<int>& nums) {
unordered_map<int, int> map;
int result;
for(int i=0;i<nums.size();i++){
map[nums[i]]++;
}
for(int i=0;i<nums.size();i++){
if(map[nums[i]]>nums.size()/2) result=nums[i];
}
return result;
}
};
标签:map,39,Offer,int,nums,result,数组
From: https://www.cnblogs.com/fly-smart/p/17674670.html