【发布时间】:2017-10-28 21:08:43
【问题描述】:
我有来自Print all unique integer partitions given an integer as input的以下代码
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]]
【问题讨论】:
标签: java