leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0354.cpp (616B)


0 class Solution {
1 public:
2 int maxEnvelopes(vector<vector<int>> &envelopes) const {
3 const int n = size(envelopes);
5 sort(begin(envelopes), end(envelopes),
6 [](const auto &a, const auto &b) { return a[0] != b[0] ? a[0] < b[0] : a[1] > b[1]; });
8 vector<int> res;
9 for (int i = 0; i < n; i++) {
10 const auto crnt = envelopes[i][1];
11 const auto it = lower_bound(begin(res), end(res), crnt);
12 if (it == end(res))
13 res.push_back(crnt);
14 else
15 *it = crnt;
16 }
18 return size(res);
19 }
20 };