-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path300_longestInreasingSub.cpp
More file actions
41 lines (37 loc) · 897 Bytes
/
Copy path300_longestInreasingSub.cpp
File metadata and controls
41 lines (37 loc) · 897 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
40
41
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
void updateTail(vector<int>& tail, int start, int end, vector<int>& nums, int i)
{
if (start == end) {
if ( end == tail.size() )
tail.push_back(nums[i]);
else
tail[start] = nums[i];
}
else {
int curr = (start+end)/2;
if (nums[i]>tail[curr])
updateTail(tail, curr+1, end, nums, i);
else
updateTail(tail, start, curr, nums, i);
}
}
int lengthOfLIS(vector<int>& nums) {
vector<int> tail;
int r = 0;
for (size_t i=0; i<nums.size(); ++i)
{
updateTail(tail, 0, tail.size(), nums, i);
}
return tail.size();
}
};
int main()
{
Solution solution;
return 0;
}