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