File size: 391 Bytes
3805fe5
bff4ec7
 
3805fe5
 
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
int lengthOfLIS(int *nums, int numsSize)

{
  int dp[100000];

  int ans = 1;

  for (int i = 0; i < numsSize; ++i) {
    dp[i] = 1;

    for (int j = 0; j < i; ++j) {
      if (nums[j] < nums[i]) {
        int candidate = dp[j] + 1;
        if (candidate > dp[i]) {
          dp[i] = candidate;
        }
      }
    }

    if (dp[i] > ans) {
      ans = dp[i];
    }

  }

  return ans;
}