数据结构:栈
时间复杂度:O(n)
空间复杂度:O(n)
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
res = [0] * len(temperatures)
stack = []
for i in range(len(temperatures)):
while stack and stack[-1][0] < temperatures[i]:
out = stack.pop()
res[out[1]] = i - out[1]
stack.append([temperatures[i], i])
return res