求讲解输入n,输出所有和为n 的连续正数序列
输入一个正数n,输出所有和为n的连续正数序列{:10_257:} def func(tsum):if tsum == 1:
return [ ]
small = 1
big = 2
mid = tsum // 2
cursum = small + big
result = [ ]
while small <= mid:
if cursum == tsum:
result.append([ i for i in range(small, big + 1) ])
big += 1
cursum += big
elif cursum < tsum:
big += 1
cursum += big
else:
cursum -= small
small += 1
return result 感谢感谢{:10_279:}
页:
[1]