2110. Number of Smooth Descent Periods of a Stock

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2110

class Solution:
    def getDescentPeriods(self, prices: List[int]) -> int:
        res = 0
        i, n = 0, len(prices)
        while i < n:
            j = i + 1
            while j < n and prices[j - 1] - prices[j] == 1:
                j += 1
            cnt = j - i
            res += (1 + cnt) * cnt // 2
            i = j
        return res