Skip to content

Commit d8fac4b

Browse files
committed
add solution of longest-increasing-subsequence
1 parent f3230f5 commit d8fac4b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
class Solution {
3+
public int lengthOfLIS(int[] nums) {
4+
5+
int[] dp = new int[nums.length];
6+
Arrays.fill(dp, 1);
7+
8+
for (int i = 1 ; i < nums.length; i++) {
9+
for (int j = i; j >= 0; j--) {
10+
if (nums[j] < nums[i]) {
11+
dp[i] = Math.max(dp[i], dp[j] + 1);
12+
}
13+
}
14+
}
15+
16+
int maxVal = 0;
17+
for (int num : dp) {
18+
if (num > maxVal) maxVal = num;
19+
}
20+
21+
return maxVal;
22+
}
23+
}

0 commit comments

Comments
 (0)