Number of Smooth Descent Periods of a Stock LeetCode solution in C++

1
class Solution {
2
public:
3
long long getDescentPeriods(vector<int> &prices) {
4
int n = prices.size();
5
int start = 0;
6
int end = 0;
7
long long ans = 1; // since, we will be starting our iteration from ist
8
// index
9

10
for (end = 1; end < n; end++) {
11
if (prices[end] == prices[end - 1] - 1) {
12
ans += end - start + 1;
13
}
14

15
else {
16
start = end;
17
ans += end - start + 1;
18
}
19
}
20

21
return ans;
22
}
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0