【剑指offer】和为S的连续正数序列(Python)
- 暴力求解
- 外部遍历到 tsum /2 就够了
- 内部遍历到 count < tsum
# -*- coding:utf-8 -*- class Solution: def FindContinuousSequence(self, tsum): # write code here if tsum < 3: return [] result = [] for i in range(1,tsum // 2 + 1): item = [] count = 0 while count < tsum: item.append(i) count += i i += 1 if count == tsum: result.append(item) return result