1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: int lengthOfLIS(vector<int>& nums) { vector<int> dp{nums[0]}; for (int i = 1; i < nums.size(); ++i) { int num = nums[i]; if (num > dp.back()) { dp.emplace_back(num); } else { auto it = lower_bound(dp.begin(), dp.end(), num); *it = num; } } return dp.size(); } };
|