_スライディングウィンドウoffer_安全性と連続正シーケンスSの数を証明

_スライディングウィンドウと連続した正のシーケンスSの数

ここに画像を挿入説明
アイデア:窓スライディング
:より転載を
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     
公開された31元の記事 ウォンの賞賛0 ビュー738

おすすめ

転載: blog.csdn.net/freedomUSTB/article/details/105012184