-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]]