From c1f17275e5879b94e0dcbc321f9dd434068ce516 Mon Sep 17 00:00:00 2001 From: mercer5 <602502833@qq.com> Date: Sun, 2 Apr 2023 11:40:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A00739=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=B8=A9=E5=BA=A6=20python=20=E7=B2=BE=E7=AE=80=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0739.每日温度.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0739.每日温度.md b/problems/0739.每日温度.md index 263a28f4..e521fbc6 100644 --- a/problems/0739.每日温度.md +++ b/problems/0739.每日温度.md @@ -271,6 +271,7 @@ class Solution { ``` Python: +> 未精简版本 ```python class Solution: @@ -291,6 +292,22 @@ class Solution: return answer ``` +> 精简版本 + +```python +class Solution: + def dailyTemperatures(self, temperatures: List[int]) -> List[int]: + # 单调栈 + answer = [0]*len(temperatures) + stack = [] + for i in range(len(temperatures)): + while len(stack)>0 and temperatures[i] > temperatures[stack[-1]]: + answer[stack[-1]] = i - stack[-1] + stack.pop() + stack.append(i) + return answer +``` + Go: > 暴力法 From a490e39206f4fd5d89165bbf0b38f982736e5309 Mon Sep 17 00:00:00 2001 From: mercer5 <602502833@qq.com> Date: Sun, 2 Apr 2023 11:50:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B90739=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=B8=A9=E5=BA=A6=20python=20=E7=B2=BE=E7=AE=80=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0739.每日温度.md | 1 - 1 file changed, 1 deletion(-) diff --git a/problems/0739.每日温度.md b/problems/0739.每日温度.md index e521fbc6..749dc972 100644 --- a/problems/0739.每日温度.md +++ b/problems/0739.每日温度.md @@ -297,7 +297,6 @@ class Solution: ```python class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: - # 单调栈 answer = [0]*len(temperatures) stack = [] for i in range(len(temperatures)):