class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
n = len(temperatures)
#从小到达,存放下标 把-1当作栈顶,0当作栈底
index_stack = [0]
res = [0] * n
for i in range(1,n):
if temperatures[i] <= temperatures[index_stack[-1]]:
index_stack.append(i)
else:
# print(index_stack[-1],i)
while len(index_stack) != 0 and temperatures[i] > temperatures[index_stack[-1]]:
#记录结果
res[index_stack[-1]] = i-index_stack[-1]
#出栈
index_stack.pop()
index_stack.append(i)
return res