Skip to content

Commit cff0147

Browse files
committed
Fixes Error
1 parent 1c45920 commit cff0147

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/main/java/com/thealgorithms/recursion/LongestIncreasingSubsequence.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ public class LongestIncreasingSubsequence {
44

55
public static int solve(int[] nums, int prev, int idx) {
66
// base case
7-
if (idx == nums.length) return 0;
7+
if (idx == nums.length) {
8+
return 0;
9+
}
810

911
// process
10-
// 1. include
11-
// 2. exclude
1212
int include = 0;
1313
if (prev == -1 || nums[idx] > nums[prev]) {
1414
include = 1 + solve(nums, idx, idx + 1);
1515
}
16-
1716
int exclude = solve(nums, prev, idx + 1);
1817
return Math.max(include, exclude);
1918
}
@@ -24,7 +23,7 @@ public int lengthOfLIS(int[] nums) {
2423
}
2524

2625
public static void main(String[] args) {
27-
int[] nums = {10, 22, 9, 33, 21, 50, 41, 60};
26+
int[] nums = {10, 9, 2, 5, 3, 7, 101, 18};
2827
LongestIncreasingSubsequence lis = new LongestIncreasingSubsequence();
2928
System.out.println("Length of LIS: " + lis.lengthOfLIS(nums));
3029
}

0 commit comments

Comments
 (0)