347. Top K Frequent Elements(重)

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

解法

class Solution {
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
        vector<int, int> output;
        unordered_map<int, int> list;
        priority_queue<int, int> find;
        for (int i = 0; i < nums.size(); i ++)
            ++ list[nums[i]];
        for (unordered_map<int, int> 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
    }
};
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,870评论 25 708
  • Just begin the research of the HBase.
    DuanSky阅读 224评论 0 1
  • DD:你好! 今天,托儿所的老师给你贴了一个五角星,你很开心地指给我看,说明你今天表现很不错! 你们托儿所每天16...
    Leice阅读 132评论 1 1
  • 近两天在读FBI教你破解身体语言,有些许感触,也渐渐的明白了之前无法理解的一些事情。 著名心理学家和作家...
    YY的世界阅读 598评论 1 2