-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay12.java
More file actions
28 lines (26 loc) · 863 Bytes
/
Day12.java
File metadata and controls
28 lines (26 loc) · 863 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
public class Day12 {
public static int lengthOfLIS(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int[] dp = new int[nums.length];
int maxLIS = 1;
for (int i = 0; i < nums.length; i++) {
dp[i] = 1;
}
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);
}
}
maxLIS = Math.max(maxLIS, dp[i]);
}
return maxLIS;
}
public static void main(String[] args) {
int[] nums = {10, 22, 9, 33, 21, 50, 41, 60, 80};
int result = lengthOfLIS(nums);
System.out.println("Length of Longest Increasing Subsequence: " + result);
}
}