Untitled
unknown
plain_text
10 months ago
770 B
21
Indexable
// problem 300. Longest Increasing Subsequence
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
// max len at each position
// --> need to know max len out of every position
int keep_track[10000];
int len = nums.size();
for (int i = 0; i < len; i ++){
keep_track[i] = 1;
}
for (int i = 1; i < len; i ++){
for (int j = 0; j < i; j ++){
if (nums[j] < nums[i]){
keep_track[i] = std::max(keep_track[j] + 1, keep_track[i]);
}
}
}
int res = 0;
for (int i = 0; i < len; i ++){
res = std::max(keep_track[i], res);
}
return res;
}
};
Editor is loading...
Leave a Comment