Skip to content

Commit ad99674

Browse files
Update stock_span_problem.py
1 parent 136bf70 commit ad99674

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

data_structures/stacks/stock_span_problem.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@
88
"""
99

1010

11-
def calculation_span(price: list[float]):
11+
def calculation_span(price: list[float]) -> list[float]:
1212
"""
1313
Calculate the span values for a given list of stock prices.
1414
Args:
1515
price (list): List of stock prices.
1616
Returns:
1717
>>> price = [10, 4, 5, 90, 120, 80]
1818
>>> calculation_span(price)
19-
[1, 1, 2, 4, 5, 6]
19+
[1.0, 1.0, 2.0, 4.0, 5.0, 6.0]
2020
>>> price = [100, 50, 60, 70, 80, 90]
2121
>>> calculation_span(price)
22-
[1, 1, 2, 3, 4, 5]
22+
[1.0, 1.0, 2.0, 3.0, 4.0, 5.0]
2323
>>> price = [5, 4, 3, 2, 1]
2424
>>> calculation_span(price)
25-
[1, 1, 2, 3, 4]
25+
[1.0, 1.0, 2.0, 3.0, 4.0]
2626
>>> price = [1, 2, 3, 4, 5]
2727
>>> calculation_span(price)
28-
[1, 2, 3, 4, 5]
28+
[1.0, 2.0, 3.0, 4.0, 5.0]
2929
>>> price = [10, 20, 30, 40, 50]
3030
>>> calculation_span(price)
31-
[1, 2, 3, 4, 5]
31+
[1.0, 2.0, 3.0, 4.0, 5.0]
3232
"""
3333
n = len(price)
3434
st = [0]
35-
s = [0] * n
36-
s[0] = 1
35+
s = [0.0] * n
36+
s[0] = 1.0
3737
for i in range(1, n):
3838
while len(st) > 0 and price[st[0]] <= price[i]:
3939
st.pop()
40-
s[i] = i + 1 if len(st) <= 0 else (i - st[0])
40+
s[i] = float(i + 1) if len(st) <= 0 else float(i - st[0])
4141
return s
4242

4343

0 commit comments

Comments
 (0)