#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 每日温度
# @param dailyTemperatures int整型一维数组 
# @return int整型一维数组
#
class Solution:
    def temperatures(self , dailyTemperatures: List[int]) -> List[int]:
        # write code here
        n = len(dailyTemperatures)
        ans = [0]*n
        stack = []#利用单调栈
        for i in range(n):
            while stack and dailyTemperatures[i]>dailyTemperatures[stack[-1]]:
                p = stack.pop()
                ans[p] = i-p
            stack.append(i)
        return ans