"Complete assignment - ready for grading" #1

Merged
reyhne merged 2 commits from develop into main 2026-07-16 18:01:48 +00:00
2 changed files with 20 additions and 2 deletions
Showing only changes of commit 28891009df - Show all commits
+17 -2
View File
@@ -153,10 +153,25 @@ public class MainExercises
body to use them instead of arrays. body to use them instead of arrays.
*/ */
public static ArrayList<ArrayList<Integer>> intPartitions(int n) { public static int[][] intPartitions(int n) {
ArrayList<ArrayList<Integer>> result = new ArrayList<>(); ArrayList<ArrayList<Integer>> result = new ArrayList<>();
backtrack(n, n, new ArrayList<>(), result); backtrack(n, n, new ArrayList<>(), result);
return result;
ArrayList<int[]> resLst = new ArrayList<int[]>();
for (int i = 0; i < result.size(); i++) {
int[] row = new int[result.get(i).size()];
for (int j = 0; j < result.get(i).size(); j++) {
row[j] = result.get(i).get(j);
}
resLst.add(row);
}
int[][] res = new int[resLst.size()][];
for (int k = 0; k < resLst.size(); k++) {
res[k] = resLst.get(k);
}
return res;
} }
private static void backtrack(int remaining, int max, private static void backtrack(int remaining, int max,
+3
View File
@@ -3,6 +3,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class MainTestPartitions { public class MainTestPartitions {
static MainExercises ex; static MainExercises ex;
@@ -63,3 +64,5 @@ public class MainTestPartitions {
assertArrayEquals(expected, ex.intPartitions(6)); assertArrayEquals(expected, ex.intPartitions(6));
} }
} }