-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path300.最长递增子序列.cpp
executable file
·71 lines (59 loc) · 1.28 KB
/
300.最长递增子序列.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// @lcpr-before-debug-begin
// @lcpr-before-debug-end
/*
* @lc app=leetcode.cn id=300 lang=cpp
* @lcpr version=21906
*
* [300] 最长递增子序列
*/
using namespace std;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// @lc code=start
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
vector<int> ans(nums.size(),1);
int maxLength=1;
for(int i=1;i<nums.size();i++)
{
for(int j=0;j<i;j++)
{
if(nums[j]<nums[i])
{
if(ans[i]<ans[j]+1)
{
ans[i]=ans[j]+1;//更新i的值,真的多了才更新,不然搞不好越来越短
if(ans[i]>maxLength)maxLength=ans[i];
}
}
}
}
return maxLength;
}
};
// @lc code=end
/*
// @lcpr case=start
// [10,9,2,5,3,7,101,18]\n
// @lcpr case=end
// @lcpr case=start
// [0,1,0,3,2,3]\n
// @lcpr case=end
// @lcpr case=start
// [7,7,7,7,7,7,7]\n
// @lcpr case=end
*/