LeetCode739 每日温度

LeetCode739 每日温度

class Solution:
    def dailyTemperatures(self, temperatures: List[int]) -> List[int]:

        ans, stack, n = [0] * len(temperatures), [], len(temperatures)

        for i in range(n):

            while stack and temperatures[stack[-1]] < temperatures[i]:
                pos = stack.pop()
                ans[pos] = i - pos
            stack.append(i)
        
        return ans

posted on 2022-09-26 21:32  solvit  阅读(17)  评论(0编辑  收藏  举报

导航