这道题多想想,心情不好不贴其他代码了
解法
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
}
};
网友评论