py3 穷解
和为S的连续正数序列
http://www.nowcoder.com/questionTerminal/c451a3fd84b64cb19485dad758a55ebe
# -*- coding:utf-8 -*- class Solution: def FindContinuousSequence(self, tsum): # write code here # tsum小于3的直接不用考虑 if tsum<3: return [] result = [] for i in range(1,(tsum+1)/2): # 穷举的话遍历到1/2 即可,本来想用math.ceil的,py2应该跟py3不一样,直接加1就完事了 tem = [] count = 0 while count <tsum: tem.append(i) count+=i i+=1 if count ==tsum: result.append(tem) # 使用内置函数进行排序 result.sort() return result