题目
得分
关键点
单调栈
代码实现
""" @File : Demo
@Author : BabyMuu
@Time : 2022/5/13 23:13
"""
from typing import List
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
stack = []
ans = [0 for _ in range(len(temperatures))]
for i, value in enumerate(temperatures):
if stack:
while stack and temperatures[stack[-1]] < value:
index = stack.pop()
ans[index] = i - index
stack.append(i)
return ans