We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ee9846 commit 4cbf92fCopy full SHA for 4cbf92f
longest-increasing-subsequence/sora0319.java
@@ -0,0 +1,24 @@
1
+import java.util.Arrays;
2
+
3
+class SolutionLIS {
4
+ public int lengthOfLIS(int[] nums) {
5
+ int n = nums.length;
6
+ int[] dp = new int[n];
7
+ Arrays.fill(dp, 1);
8
9
+ for (int current = 1; current < n; current++) {
10
+ for (int prev = 0; prev < current; prev++) {
11
+ if (nums[prev] < nums[current]) {
12
+ dp[current] = Math.max(dp[current], dp[prev] + 1);
13
+ }
14
15
16
17
+ int maxLength = 0;
18
+ for (int len : dp) {
19
+ maxLength = Math.max(maxLength, len);
20
21
+ return maxLength;
22
23
+}
24
0 commit comments