class Solution {
public:
/**
* @param nums: A list of integers
* @return: The majority number
*/
int majorityNumber(vector<int> nums) {
// write your code here
map<int,int>m1;
for(auto c:nums) ++m1[c];
for(auto c:m1)
if(c.second>nums.size()/2)
return c.first;
}
};
LintCode(easy)主元素
最新推荐文章于 2020-07-12 12:05:10 发布