-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_739.py
More file actions
30 lines (26 loc) · 963 Bytes
/
Copy pathtask_739.py
File metadata and controls
30 lines (26 loc) · 963 Bytes
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
from typing import List
from bisect import bisect_right
class Solution:
def dailyTemperatures(self, temp: List[int]) -> List[int]:
n = len(temp)
ans = n * [0]
pz = {}
for i, x in enumerate(temp):
if x not in pz:
pz[x] = []
pz[x].append(i)
for i in range(n-1):
mn = int(1e9+228)
for next in range(temp[i]+1, 101):
if next not in pz:
continue
ln = len(pz[next])
idx = bisect_right(pz[next], i)
if pz[next][ln-1] < i or idx == ln:
continue
mn = min(mn, pz[next][idx]-i)
ans[i] = 0 if mn == int(1e9+228) else mn
return ans
print(Solution().dailyTemperatures(temp=[73,74,75,71,69,72,76,73]))
print(Solution().dailyTemperatures(temp=[30,40,50,60]))
print(Solution().dailyTemperatures(temp=[30,60,90]))