2110. Number of Smooth Descent Periods of a Stock Medium

@problem@discussion
#Array#Math#Dynamic Programming



1/**
2 * [2110] Number of Smooth Descent Periods of a Stock
3 *
4 * You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the i^th day.
5 * A smooth descent period of a stock consists of one or more contiguous days such that the price on each day is lower than the price on the preceding day by exactly 1. The first day of the period is exempted from this rule.
6 * Return the number of smooth descent periods.
7 *  
8 * Example 1:
9 * 
10 * Input: prices = [3,2,1,4]
11 * Output: 7
12 * Explanation: There are 7 smooth descent periods:
13 * [3], [2], [1], [4], [3,2], [2,1], and [3,2,1]
14 * Note that a period with one day is a smooth descent period by the definition.
15 * 
16 * Example 2:
17 * 
18 * Input: prices = [8,6,7,7]
19 * Output: 4
20 * Explanation: There are 4 smooth descent periods: [8], [6], [7], and [7]
21 * Note that [8,6] is not a smooth descent period as 8 - 6 ≠ 1.
22 * 
23 * Example 3:
24 * 
25 * Input: prices = [1]
26 * Output: 1
27 * Explanation: There is 1 smooth descent period: [1]
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= prices.length <= 10^5
33 * 	1 <= prices[i] <= 10^5
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock/
39// discuss: https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn get_descent_periods(prices: Vec<i32>) -> i64 {
45        
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_2110() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.