-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathp300.c
33 lines (33 loc) · 800 Bytes
/
p300.c
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
int lengthOfLIS(int* nums, int numsSize){
short arr[2503] = { 0, nums[0], 0 };
short res = 1;
int* numEnd = nums + numsSize;
for (int* p = nums + 1; p != numEnd; ++p)
{
short val = (short)(*p);
short count = res;
short found = 1;
while (count > 0)
{
short it = found;
short step = count / 2;
it += step;
if (arr[it] < val)
{
found = ++it;
count -= step + 1;
}
else
count = step;
}
if (found > res)
{
arr[++res] = val;
}
else if (val < arr[found])
{
arr[found] = val;
}
}
return res;
}