-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path739.py
37 lines (31 loc) · 1.06 KB
/
739.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# [ LeetCode ] 739. Daily Temperatures
def solution(temperatures: list[int]) -> list[int]:
answer: list[int] = [0] * len(temperatures)
stack: list[int] = []
for current_day, temperature in enumerate(temperatures):
while stack and temperatures[stack[-1]] < temperature:
previous_day: int = stack.pop()
difference: int = current_day - previous_day
answer[previous_day] = difference
stack.append(current_day)
return answer
def another_solution(temperatures: list[int]) -> list[int]:
pass
if __name__ == "__main__":
cases: list[dict[str, list[int] | list[int]]] = [
{
"input": {
"temperatures": []
},
"output": []
},
{
"input": {
"temperatures": []
},
"output": []
}
]
for case in cases:
assert case["output"] == solution(**case["input"])
assert case["output"] == another_solution(**case["input"])