Advertisement
nikunjsoni

300

May 15th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int lengthOfLIS(vector<int>& nums) {
  4.         vector<int> lis;
  5.         for(auto num : nums){
  6.             int pos = lower_bound(lis.begin(), lis.end(), num)-lis.begin();
  7.             if(pos == lis.size())
  8.                 lis.push_back(num);
  9.             else
  10.                 lis[pos] = num;
  11.         }
  12.         return lis.size();
  13.     }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement