Number of Smooth Descent Periods of a Stock

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class Solution:
    def getDescentPeriods(self, prices: List[int]) -> int:
        ans = dp = 1
        for i in range(1, len(prices)):
            if prices[i] == prices[i - 1] - 1:
                dp = dp + 1
            else:
                dp = 1
            ans = ans + dp
        return ans