其他分享
首页 > 其他分享> > 和为S的连续正数序列

和为S的连续正数序列

作者:互联网

双指针滑动法

class Solution:
    def FindContinuousSequence(self,tsum):
        # write code here
        if tsum < 3:
            return []
        res = []
        low = 1
        high = 2
        while low < high:
            sum = (low + high) * (high - low + 1) / 2
            if sum == tsum:
                res.append(range(low,high+1))
                low += 1
            elif sum < tsum:
                high += 1
            else:
                low += 1
        return res

标签:tsum,return,res,sum,high,连续,序列,正数,low
来源: https://blog.csdn.net/weixin_43994113/article/details/90733971