Advertisement
nikunjsoni

354

May 13th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxEnvelopes(vector<vector<int>>& envelopes) {
  4.         // Sort the envelopes.
  5.         sort(envelopes.begin(), envelopes.end(), [](auto &a, auto &b){return a[0]<b[0] || (a[0] == b[0] && a[1] > b[1]);});
  6.        
  7.         // Find lis of height.
  8.         vector<int> seq;
  9.         for(auto &env: envelopes){
  10.             auto it = lower_bound(seq.begin(), seq.end(), env[1]);
  11.             if(it == seq.end())
  12.                 seq.push_back(env[1]);
  13.             else
  14.                 seq[it-seq.begin()] = env[1];
  15.         }
  16.         return seq.size();
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement