300. Longest Increasing Subsequence Given an integer array ums`, return the length of the longest strictly increasing subsequence.
Given a[]
f[i] The length of the longest increasing subsequence with the last element being a[i]
Answer:
int lengthOfLIS(vector<int> &nums) {
vector<int> f(nums.size());
int n = nums.size();
for (int i = 0; i < n; i++) {
f[i] = 1;
int maxv = 0;
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j]) {
maxv = max(maxv, f[j]);
}
}
f[i] = maxv + 1;
}
return *max_element(f.begin(), f.end());
}