这样写,正确创建优先级队列
class mycomparison {
public:
bool operator()(const pair<int, int>& lhs, const pair<int, int>& rhs) {
return lhs.second > rhs.second;
}
};
vector<int> topKFrequent(vector<int>& nums, int k) {
priority_queue<pair<int,int>,vector<pair<int,int>>,mycomparison>pri_que;
这样写 编译器报错,我的lambda表达式写错了吗?
priority_queue<pair<int,int>,vector<pair<int,int>>,[](pair<int,int>&map1,pair<int,int>&map2)
{return map1.second>map2.second;} >pri_que;
错误信息:
error: a lambda expression cannot appear in this context
priority_queue<pair<int,int>,vector<pair<int,int>>,[](pair<int,int>&map1,pair<int,int>&map2)