#include<vector> #include<algorithm> #include<climits> using std::vector;
classSolution { public: intlengthOfLIS(vector<int> &nums) { // dp[i] is the length of the longest strictly increasing subsequence ending with nums[i] // dp[i] = max{dp[j]}(nums[j]<nums[i] && j<i) + 1; int i, j, n = nums.size(); int max_val = INT_MIN; vector<int> dp(n, 1);
for (i = 0; i < n; i++) { max_val = INT_MIN; for (j = 0; j < i; j++) { if (nums[j] < nums[i]) { max_val = std::max(max_val, dp[j]); } } if (max_val != INT_MIN) { dp[i] = max_val + 1; }else{ dp[i] = 1; } } return *std::max_element(dp.begin(), dp.end()); } };