剑指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
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