- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution300.java
More file actions
Latest commit
executable file
·38 lines (31 loc) · 913 Bytes
/
Copy pathSolution300.java
File metadata and controls
executable file
·38 lines (31 loc) · 913 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
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.List;
/**
* Created by slade on 2019/8/14.
*/
publicclassSolution300 {
publicintlengthOfLIS(int[] nums) {
if (nums.length == 0) return0;
if (nums.length == 1) return1;
intmaxValue = 0;
int[] dp = newint[nums.length];
dp[0] = 1;
for (inti = 1; i < nums.length; i++) {
dp[i] = 1;
for (intj = 0; j < i; j++) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
maxValue = Math.max(maxValue, dp[i]);
}
System.out.println(Arrays.toString(dp));
returnmaxValue;
}
publicstaticvoidmain(String[] args) {
Solution300s = newSolution300();
int[] arr = {2, 2};
System.out.println(s.lengthOfLIS(arr));
}
}