剑指offer python版 为s的连续正数序列

def sum_to_s(s):
    a, b = 1, 2
    ret = []
    while a < s / 2 + 1:
        if sum(range(a, b+1)) == s:
            ret.append(range(a, b+1))
            a += 1
        elif sum(range(a, b+1)) < s:
            b += 1
        else:
            a += 1
    return ret

 

posted @ 2018-10-29 11:20  findtruth123  阅读(258)  评论(0编辑  收藏  举报