-2
我有以下代码从Print all unique integer partitions given an integer as input整数分区在Java商店输出阵列中的
void printPartitions(int target, int maxValue, String suffix) {
if (target == 0)
System.out.println(suffix);
else {
if (maxValue > 1)
printPartitions(target, maxValue-1, suffix);
if (maxValue <= target)
printPartitions(target-maxValue, maxValue, maxValue + " " + suffix);
}
}
当调用printPartitions(4,4, “”);它给放出来这样
1 1 1 1
1 1 2
2 2
1 3
4
我怎样才能获得输出像数组这样
[1,1,1,1],[1,1,2],[2, 2],[1,3],[4]]