class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
stack=[]
res=[0]*len(temperatures)
for i,item in enumerate(temperatures):
if not stack:
stack.append([i,item])
else:
while stack and stack[-1][1]<item:
index,cur_item=stack.pop()
res[index]=i-index
stack.append([i,item])
return res
LEETCODE 739. 每日温度
最新推荐文章于 2024-11-17 06:32:34 发布