Number of Smooth Descent Periods of a Stock LeetCode solution in JavaScript

1
var getDescentPeriods = function (prices) {
2
const n = prices.length;
3

4
let left = 0;
5
let totRes = 0;
6

7
while (left < n) {
8
let count = 1;
9

10
let right = left + 1;
11

12
while (right < n && prices[right] + 1 === prices[right - 1]) {
13
count += right - left + 1;
14
++right;
15
}
16

17
totRes += count;
18

19
left = right;
20
}
21

22
return totRes;
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0