347. Top K Frequent Elements(重)

这道题多想想,心情不好不贴其他代码了

解法

class Solution {
public:
    vector topKFrequent(vector& nums, int k) {
        vector output;
        unordered_map list;
        priority_queue find;
        for (int i = 0; i < nums.size(); i ++)
            ++ list[nums[i]];
        for (unordered_map iterator i = list.begin(); i != list.end(); i ++)
            find.push(make_pair(i -> second, i -> first));
        while (find.size() != k)
            find.pop();
        while (find.size())
            output
    }
};

你可能感兴趣的:(347. Top K Frequent Elements(重))