Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 45aa87c

Browse files
add 2110
1 parent 59e67ad commit 45aa87c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2110|[Number of Smooth Descent Periods of a Stock](https://leetcode.com/problems/number-of-smooth-descent-periods-of-a-stock/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2110.java) ||Medium||
1112
|2109|[Adding Spaces to a String](https://leetcode.com/problems/adding-spaces-to-a-string/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2109.java) ||Medium||
1213
|2108|[Find First Palindromic String in the Array](https://leetcode.com/problems/find-first-palindromic-string-in-the-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2108.java) ||Easy||
1314
|2103|[Rings and Rods](https://leetcode.com/problems/rings-and-rods/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2103.java) ||Easy||
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2110 {
4+
public static class Solution1 {
5+
public long getDescentPeriods(int[] prices) {
6+
long ans = prices.length;
7+
for (int i = 0; i < prices.length; i++) {
8+
long startI = i;
9+
while (i + 1 < prices.length && prices[i] - 1 == prices[i + 1]) {
10+
i++;
11+
}
12+
long totalNum = i - startI + 1;
13+
if (totalNum > 1) {
14+
ans += ((totalNum - 1) * totalNum) / 2;
15+
}
16+
}
17+
return ans;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)