mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Add leetcode 300
This commit is contained in:
parent
e8779ea3d3
commit
5e80796721
19
LeetCode-CN/300.cpp
Normal file
19
LeetCode-CN/300.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
class Solution {
|
||||
public:
|
||||
int lengthOfLIS(vector<int>& nums) {
|
||||
int N = nums.size();
|
||||
vector<int> dp(N);
|
||||
for (int i = 0; i < N; i++) {
|
||||
dp[i] = 1;
|
||||
}
|
||||
for (int i = 1; i < N; i++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (nums[i] > nums[j]) {
|
||||
dp[i] = max(dp[i], dp[j] + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return *max_element(dp.begin(), dp.end());
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user