方式一:lamda表达式
auto lamda = [](const pair<int, int>& lhs, const pair<int, int>& rhs) {
return lhs.second > rhs.second;
};
priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(lamda)> pri_que{lamda};
方式二:仿函数
class Solution {
public:
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;
}
方式三:关系运算符重载?