标签:back 列表 elf dai problem 位置 矩形 ret for
单调栈 stack
https://leetcode-cn.com/problems/daily-tempratures/
根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高超过该日的天数。如果之后都不会升高,请在该位置用 0 来代替。
例如,给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]。
提示:气温 列表长度的范围是 [1, 30000]。每个气温的值的均为华氏度,都是在 [30, 100] 范围内的整数。
使用单调递减stack
class Solution(object):
def dailyTemperatures(self, T):
"""
:type T: List[int]
:rtype: List[int]
"""
stack = []
ans = [0]*len(T)
for i,t in enumerate(T):
while stack and t > T[stack[-1]]:
ans[stack[-1]] = i-stack[-1]
stack.pop()
stack.append(i)
return ans
二进制中最大的矩形
标签:back 列表 elf dai problem 位置 矩形 ret for
原文地址:https://www.cnblogs.com/bonelee/p/12045947.html