From c369db528f0953160e355ef30ca684c879632a04 Mon Sep 17 00:00:00 2001 From: lichun-chen <81766312+lichun-chen@users.noreply.github.com> Date: Wed, 7 Jul 2021 20:47:03 -0500 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200739.=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=B8=A9=E5=BA=A6.md=20=20Python3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0739.每日温度.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/problems/0739.每日温度.md b/problems/0739.每日温度.md index e72fd6a4..fd78838e 100644 --- a/problems/0739.每日温度.md +++ b/problems/0739.每日温度.md @@ -211,7 +211,24 @@ Java: } ``` Python: - +''' Python3 +class Solution: + def dailyTemperatures(self, temperatures: List[int]) -> List[int]: + answer = [0]*len(temperatures) + stack = [0] + for i in range(1,len(temperatures)): + # 情况一和情况二 + if temperatures[i]<=temperatures[stack[-1]]: + stack.append(i) + # 情况三 + else: + while len(stack) != 0 and temperatures[i]>temperatures[stack[-1]]: + answer[stack[-1]]=i-stack[-1] + stack.pop() + stack.append(i) + + return answer +''' Go: > 暴力法