-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
29 lines (26 loc) · 932 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
int maxEnvelopes(vector<vector<int>>& envelopes) {
int n = envelopes.size();
sort(envelopes.begin(), envelopes.end(),
[](const vector<int>& a, const vector<int>& b) {
if (a[0] == b[0]) return a[1] > b[1];
return a[0] < b[0];
});
vector<array<int, 2>> result;
for (const auto& e : envelopes) {
auto it = lower_bound(
result.begin(), result.end(), array<int, 2>{e[0], e[1]},
[](const array<int, 2>& value,
const array<int, 2>& target) -> bool {
return value[0] < target[0] && value[1] < target[1];
});
if (it == result.end()) {
result.push_back({e[0], e[1]});
} else {
*it = {e[0], e[1]};
}
}
return result.size();
}
};