-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path300.cpp
More file actions
32 lines (29 loc) · 748 Bytes
/
Copy path300.cpp
File metadata and controls
32 lines (29 loc) · 748 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
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
int len = nums.size();
if(len == 0)return 0;
vector<int> p;
int* dp = new int[len];
p.push_back(nums[0]);
dp[0] = 1;
int ma = 1;
for(int i = 1; i < len; ++i)
{
auto iter = lower_bound(p.begin(), p.end(), nums[i]);
if(iter == p.end())
{
dp[i] = p.size() + 1;
if(dp[i] > ma)ma = dp[i];
p.push_back(nums[i]);
}
else
{
dp[i] = iter - p.begin() + 1;
if(dp[i] > ma)ma = dp[i];
*iter = nums[i];
}
}
return ma;
}
};