【Leetcode_easy】961. N-Repeated Element in Size 2N Array

problem

961. N-Repeated Element in Size 2N Array

solution:

class Solution {
public:
    int repeatedNTimes(vector<int>& A) {
        unordered_map<int, int> amap;
        for(auto a:A)
        {
            amap[a]++;
        }
        int max_num = 0, max_val;
        for(auto a:amap)
        {
            if(a.second>max_num)
            {
                max_num = a.second;
                max_val = a.first;
            }
        }
        return max_val;
    }
};

 

 

参考

1. Leetcode_easy_961. N-Repeated Element in Size 2N Array;

posted on 2019-07-26 19:50  鹅要长大  阅读(158)  评论(0编辑  收藏  举报

导航