-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsol.py
32 lines (26 loc) · 891 Bytes
/
sol.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
from typing import List, Optional
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
answers = [0] * len(temperatures)
stacked = []
for idx, temp in enumerate(temperatures[::-1]):
# print(idx, temp)
if not stacked:
stacked.append((temp, idx))
continue
while stacked:
if stacked[-1][0] < temp:
stacked.pop()
continue
print(idx)
_, last_idx = stacked[-1]
diff = idx - last_idx
answers[idx] = diff
break
stacked.append((temp, idx))
answers.reverse()
return answers
temperatures = [73,74,75,71,69,72,76,73]
s = Solution()
res = s.dailyTemperatures(temperatures)
print(res)