#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
class Solution{
public:
int numberOfWeakCharacters(vector<vector<int>>& properties){
int res = 0;
sort(properties.begin(), properties.end(), [](const auto & c0, const auto & c1){
return c0[0] == c1[0] ? c0[1]<c1[1] : c0[0] > c1[0];
});
int maxd = properties[0][1];
int len = properties.size();
for(int i=1; i<len; i++){
if(maxd>properties[i][1]) res++;
else maxd = properties[i][1];
}
return res;
}
};
int main(void){
vector<vector<int>> a{{1,7},{10,4},{4,3},{4,7}};
Solution samp;
int num = samp.numberOfWeakCharacters(a);
for(auto & outer : a){
for(auto & inner:outer)
cout<<inner<<",";
cout<<endl;
}
cout<<"There are "<<num<<" weak chars"<<endl;
}
LeetCode第1996题 游戏中弱角色的数量(C++)
最新推荐文章于 2024-05-13 09:55:25 发布