【数组】和为S的连续正数序列

class Solution:
    def FindContinuousSequence(self, tsum):
        # write code here
        l = r = sum_ = 1
        res = []
        while l <= tsum//2:
            while sum_ < tsum:
                r += 1
                sum_ += r
            if sum_ == tsum:
                res.append(range(l,r+1))
            sum_ -= l
            l += 1
        return res

你可能感兴趣的:(【数组】和为S的连续正数序列)