def summation(total, result = []):
begin = 1
totalResult = []
if len(result) > 0: begin = max(result) + 1
for i in range(begin, total):
if total - i > i:
thisResult = result + [i] + [total - i];
totalResult.append(thisResult);
totalResult += summation(total - i, result + [i])
return totalResult;
def printResult(totalResult):
'''
打印summation計算出來的結果集totalResult
'''
for result in totalResult:
print(result)
不解釋,公司用了很久的一道面試題,要求用java做的