Class Solution
java.lang.Object
g2101_2200.s2110_number_of_smooth_descent_periods_of_a_stock.Solution
2110 - Number of Smooth Descent Periods of a Stock.<p>Medium</p>
<p>You are given an integer array <code>prices</code> representing the daily price history of a stock, where <code>prices[i]</code> is the stock price on the <code>i<sup>th</sup></code> day.</p>
<p>A <strong>smooth descent period</strong> of a stock consists of <strong>one or more contiguous</strong> days such that the price on each day is <strong>lower</strong> than the price on the <strong>preceding day</strong> by <strong>exactly</strong> <code>1</code>. The first day of the period is exempted from this rule.</p>
<p>Return <em>the number of <strong>smooth descent periods</strong></em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> prices = [3,2,1,4]</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong> There are 7 smooth descent periods:</p>
<p>[3], [2], [1], [4], [3,2], [2,1], and [3,2,1]</p>
<p>Note that a period with one day is a smooth descent period by the definition.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> prices = [8,6,7,7]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> There are 4 smooth descent periods: [8], [6], [7], and [7]</p>
<p>Note that [8,6] is not a smooth descent period as 8 - 6 \u2260 1.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> prices = [1]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> There is 1 smooth descent period: [1]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= prices.length <= 10<sup>5</sup></code></li>
<li><code>1 <= prices[i] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
getDescentPeriods
public long getDescentPeriods(int[] prices)
-