本文主要是介绍Leetcode 2110. Number of Smooth Descent Periods of a Stock [Python],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
DP。DP的每一位表示的是以此位数字为结尾的光滑下降序列。则,如果prices[i] + 1 == prices[i-1]。那么无论有多少光滑下降序列以prices[i-1]结尾,都有这样的数量再加上1(也就是prices[i]自己)结尾于prices[i].
class Solution:def getDescentPeriods(self, prices: List[int]) -> int:base = len(prices)if base == 1:return 1dp = [1 for _ in range(base)]for i in range(1, base):if prices[i] + 1 == prices[i-1]:dp[i] += dp[i-1]return sum(dp)
这篇关于Leetcode 2110. Number of Smooth Descent Periods of a Stock [Python]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!