LeetCode 2110 - Number of Smooth Descent Periods of a Stock
Difficulty: medium
Problem Description
English (Number of Smooth Descent Periods of a Stock)
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.
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.
Return the number of smooth descent periods.
Example 1:
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
Constraints:
1 <= prices.length <= 10^5
1 <= prices[i] <= 10^5
Chinese (股票平滑下跌阶段的数目)
给你一个整数数组 prices
,表示一支股票的历史每日股价,其中 prices[i]
是这支股票第 i
天的价格。
一个 平滑下降的阶段 定义为:对于 连续一天或者多天 ,每日股价都比 前一日股价恰好少 1
,这个阶段第一天的股价没有限制。
请你返回 平滑下降阶段 的数目。
示例 1:
1 |
|
示例 2:
1 |
|
示例 3:
1 |
|
提示:
1 <= prices.length <= 10^5
1 <= prices[i] <= 10^5
Solution
C++
1 |
|
LeetCode 2110 - Number of Smooth Descent Periods of a Stock
http://wasprime.github.io/Algorithm/LeetCode/DynamicProgramming/LeetCode-2110-Number-of-Smooth-Descent-Periods-of-a-Stock/