-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSolution.java
36 lines (33 loc) · 939 Bytes
/
Solution.java
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
package leetcode.algo.dynamic_programming.leet_zh_300;
public class Solution {
/*
* 执行用时 : 49 ms
* 内存消耗 : 35.1 MB
* O(n^2)
* */
public int lengthOfLIS(int[] nums) {
if (nums.length == 0)
return 0;
int[] res = new int[nums.length];
for (int i = 0; i < nums.length; i++) {
res[i] = 1;
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i] && res[j] + 1 > res[i]) {
res[i] = res[j] + 1;
}
}
}
int max = 0;
for (int i = 0; i < res.length; i++) {
if (max <= res[i]) {
max = res[i];
}
}
return max;
}
public static void main(String[] args) {
Solution ss = new Solution();
int[] nums = {10, 9, 2, 5, 3, 7, 101, 18};
System.out.println(ss.lengthOfLIS(nums));
}
}