_ Prove safety offer_ sliding window and the number of consecutive positive sequence S

_ Sliding window and the number of consecutive positive sequence S

Here Insert Picture Description
Ideas: sliding window
Reprinted from:
https://blog.csdn.net/gui951753/article/details/92416352

# -*- coding:utf-8 -*-
class Solution:
    def FindContinuousSequence(self, tsum):
        # write code here
        if tsum < 3:
            return []
        results = []
        p_low = 1
        p_high = 2
        while p_low < p_high:
            if sum(range(p_low,p_high+1))==tsum:
                results.append((range(p_low,p_high+1)))
                p_high += 1
            elif sum(range(p_low,p_high+1))<tsum:
                p_high += 1
            else:
                p_low += 1
        return results     
Published 31 original articles · won praise 0 · Views 738

Guess you like

Origin blog.csdn.net/freedomUSTB/article/details/105012184