-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path300.cpp
More file actions
39 lines (38 loc) · 957 Bytes
/
300.cpp
File metadata and controls
39 lines (38 loc) · 957 Bytes
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
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
if(nums.empty())
return 0;
int n = nums.size();
int res = 1;
vector<int> dp(n,1);
for(int i = 1; i<n; i++){
for(int j=0; j<i; j++){
if(nums[i] > nums[j] && dp[i]<dp[j]+1){
dp[i] = dp[j] + 1;
res = max(res,dp[i]);
}
}
}
return res;
}
};
class Solution {
public:
int lengthOfLIS(vector<int>& arr) {
int n = arr.size();
if(n==0)
return 0;
vector<int> aux(n,0);
int lenght = 1;
aux[0] = arr[0];
for(int i=1; i<n; i++){
auto it = lower_bound(aux.begin(), aux.begin()+lenght, arr[i]);
if(it==aux.begin()+lenght)
aux[lenght++] = arr[i];
else
*it = arr[i];
}
return lenght;
}
};