Skip to content

Commit f1b3992

Browse files
committed
Time: 47 ms (87.31%), Space: 30 MB (47.02%) - LeetHub
1 parent ae844b3 commit f1b3992

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# time complexity: O(n)
2+
# space complexity: O(1)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def getDescentPeriods(self, prices: List[int]) -> int:
8+
prev = prices[0]
9+
count = 1
10+
result = 1
11+
for i in range(1, len(prices)):
12+
price = prices[i]
13+
if price == prev - 1:
14+
count += 1
15+
else:
16+
count = 1
17+
prev = price
18+
result += count
19+
20+
return result
21+
22+
23+
prices = [3, 2, 1, 4]
24+
print(Solution().getDescentPeriods(prices))
25+
prices = [8, 6, 7, 7]
26+
print(Solution().getDescentPeriods(prices))
27+
prices = [1]
28+
print(Solution().getDescentPeriods(prices))

0 commit comments

Comments
 (0)