LeetCode-739 每日温度
Table of Contents
LeetCode-739 每日温度 #
Solution 1 #
维护一个单调栈.
代码如下:
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
s = []
ans = [0 for _ in temperatures]
for i in range(len(temperatures) - 1, -1, -1):
while s and temperatures[s[-1]] <= temperatures[i]:
s.pop()
ans[i] = s[-1] - i if s else 0
s.append(i)
return ans