class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
int len = 0, max = 0;
int n = nums.size();
vector<int> L(n,1);
for (int i = 0; i< n; i++) {
for (int j = i+1; j<n; j++) {
if (nums[j]>nums[i] && L[j]<L[i]+1) {
L[j] = L[i]+1;
}
}
}
for (int i = 0; i<n; i++) {
if (max<L[i]) max = L[i];
}
return max;
}
};
No comments:
Post a Comment