LintCode(easy)主元素

来源:互联网 发布:阿里云邮如何改密码 编辑:程序博客网 时间:2024/04/27 18:46
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;    }};
0 0
原创粉丝点击