Leetcode 739. 每日温度 (每日一题 20211014)
生活随笔
收集整理的這篇文章主要介紹了
Leetcode 739. 每日温度 (每日一题 20211014)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
請根據每日 氣溫 列表 temperatures?,請計算在每一天需要等幾天才會有更高的溫度。如果氣溫在這之后都不會升高,請在該位置用?0 來代替。示例 1:輸入: temperatures = [73,74,75,71,69,72,76,73]
輸出:?[1,1,4,2,1,1,0,0]
示例 2:輸入: temperatures = [30,40,50,60]
輸出:?[1,1,1,0]
示例 3:輸入: temperatures = [30,60,90]
輸出: [1,1,0]鏈接:https://leetcode-cn.com/problems/daily-temperaturesclass Solution:def dailyTemperatures(self, temperatures: List[int]) -> List[int]:stack, target = [], [0] * len(temperatures)for i, num in enumerate(temperatures):while stack and num > temperatures[stack[-1]]:index = stack.pop()target[index] = i - indexstack.append(i)return target
總結
以上是生活随笔為你收集整理的Leetcode 739. 每日温度 (每日一题 20211014)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 91. 解码方法 (每
- 下一篇: Leetcode 153. 寻找旋转排序