Skip to content

Commit d09592e

Browse files
committed
add daily temperature
1 parent a08926e commit d09592e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/daily_temperature.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
6+
res = [0] * len(temperatures)
7+
stack = []
8+
9+
for index, temp in enumerate(temperatures):
10+
while stack and temp > stack[-1][0]:
11+
stackT, stackInd = stack.pop()
12+
res[stackInd] = index - stackInd
13+
stack.append([temp, index])
14+
return res

tests/test_daily_temperature.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from daily_temperature import Solution
2+
3+
testcase = [
4+
{"testcase": [73, 74, 75, 71, 69, 72, 76, 73], "result": [1, 1, 4, 2, 1, 1, 0, 0]}
5+
]
6+
7+
8+
def test_daily_temperature():
9+
for tc in testcase:
10+
temperatures = tc["testcase"]
11+
ans = Solution().dailyTemperatures(temperatures)
12+
assert ans == tc["result"]

0 commit comments

Comments
 (0)