-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLc300.java
More file actions
31 lines (28 loc) · 735 Bytes
/
Lc300.java
File metadata and controls
31 lines (28 loc) · 735 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
package leetcode;
import java.util.Arrays;
/**
* @author Kuma
* @date 2021年1月24日
* 300.最长递增子序列
*/
public class Lc300 {
public static int lengthOfLIS(int[] nums) {
int[] dp = new int[nums.length];
Arrays.fill(dp, 1);
int max = 0;
for (int i = 1; i < nums.length; i++) {
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j]){
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
max = Math.max(dp[i], max);
}
return max;
}
public static void main(String[] args) {
int[] a = {10,9,2,5,3,7,101,18};
int s = lengthOfLIS(a);
System.out.println(s);
}
}