add: 220128-CN

This commit is contained in:
Lam Haoyin 2022-01-28 17:49:03 +08:00
parent ec86560952
commit 945c416f90
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 25 additions and 1 deletions

24
2201/220128-CN.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <vector>
#include <iostream>
class Solution {
public:
static int numberOfWeakCharacters(std::vector<std::vector<int>>& properties) {
std::sort(properties.begin(), properties.end(), [](const std::vector<int>& x, const std::vector<int>& y) {
if (x[0] - y[0])
return x[0] > y[0];
return x[1] < y[1];
});
int ret = 0, max = -1;
for (const auto& i : properties)
if ((max = std::max(i[1], max)) > i[1])
++ret;
return ret;
}
};
int main() {
std::vector<std::vector<int>> args = {{1,1},{2,1},{2,2},{1,2}};
std::cout << Solution::numberOfWeakCharacters(args);
return 0;
}

View File

@ -3,4 +3,4 @@ PROJECT(2201)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2201 220127.cpp)
ADD_EXECUTABLE(2201 220128-CN.cpp)