Advertisement
Araf_12

LIS

Oct 22nd, 2024
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. int lengthOfLIS(vector<int>& nums) {
  2.   int n = nums.size();
  3.   vector<int> ans;
  4.   ans.push_back(nums[0]);
  5.   for (int i = 1; i < n; i++) {
  6.     if (nums[i] > ans.back()) {
  7.       ans.push_back(nums[i]);
  8.     } else {
  9.       auto low = lower_bound(ans.begin(), ans.end(), nums[i]) - ans.begin();
  10.       ans[low] = nums[i];
  11.     }
  12.   }
  13.   return ans.size();
  14. }
  15.  
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement