---
# System prepended metadata

title: 2110. Number of Smooth Descent Periods of a Stock
tags: [Leetcode, Medium]

---

# 2110. Number of Smooth Descent Periods of a Stock
###### tags: `Leetcode` `Medium`
Link: https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock/description/
## 思路
One pass
每次找到以当前元素为首的descent sequence 假设这个seq的长度是```n``` 那么这个seq里面所有数字能构成的smooth descent periods数量就是```(1+n)*n/2```
下一个遍历的元素就是seq结尾元素的下一个
因此这个元素都只遍历了一遍
## Code
```python=
class Solution:
    def getDescentPeriods(self, prices: List[int]) -> int:
        i = 0
        ans = 0
        while i<len(prices):
            j = i
            while j+1<len(prices) and prices[j]==prices[j+1]+1:
                j += 1
            ans += ((j-i+1+1)*(j-i+1))//2 
            i = j+1

        return ans
```