您的位置:首页 > 编程语言 > C语言/C++

c++ map根据value排序以及lamda表达式的应用

2016-05-03 10:20 423 查看
vector<int> topKFrequent(vector<int>& nums, int k) {
map<int, int> m;
vector<pair<int, int>> temp;
vector<int> res;
for (auto n : nums) {
m
++;
}
for (auto i : m) {
temp.push_back(i);
}
std::sort(temp.begin(), temp.end(), [](pair<int, int>& a, pair<int, int>& b) {return a.second > b.second;});
for (auto i:temp) {
res.push_back(i.first);
k--;
if (k == 0) return res;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: