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 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200739.=E6=AF=8F?= =?UTF-8?q?=E6=97=A5=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: > 暴力法 From 309ecc9c3508bbea2276411c1c154b9f3906e77e Mon Sep 17 00:00:00 2001 From: lichun-chen <81766312+lichun-chen@users.noreply.github.com> Date: Wed, 7 Jul 2021 20:49:20 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200739.=E6=AF=8F?= =?UTF-8?q?=E6=97=A5=E6=B8=A9=E5=BA=A6=20=20Python3=20=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0739.每日温度.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/0739.每日温度.md b/problems/0739.每日温度.md index fd78838e..8ad79fe3 100644 --- a/problems/0739.每日温度.md +++ b/problems/0739.每日温度.md @@ -211,7 +211,7 @@ Java: } ``` Python: -''' Python3 +``` Python3 class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: answer = [0]*len(temperatures) @@ -228,7 +228,7 @@ class Solution: stack.append(i) return answer -''' +``` Go: > 暴力法 From 480939a1cd59b910071078232bcf4e8ec7c7a97f Mon Sep 17 00:00:00 2001 From: lichun-chen <81766312+lichun-chen@users.noreply.github.com> Date: Thu, 8 Jul 2021 11:00:02 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B00496.=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E6=9B=B4=E5=A4=A7=E5=85=83=E7=B4=A0I.md=20Python3?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0496.下一个更大元素I.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/problems/0496.下一个更大元素I.md b/problems/0496.下一个更大元素I.md index 88e89e52..0404e434 100644 --- a/problems/0496.下一个更大元素I.md +++ b/problems/0496.下一个更大元素I.md @@ -185,3 +185,26 @@ public: 建议大家把情况一二三想清楚了,先写出版本一的代码,然后在其基础上在做精简! +## 其他语言版本 + +Python: +```python3 +class Solution: + def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]: + result = [-1]*len(nums1) + stack = [0] + for i in range(1,len(nums2)): + # 情况一情况二 + if nums2[i]<=nums2[stack[-1]]: + stack.append(i) + # 情况三 + else: + while len(stack)!=0 and nums2[i]>nums2[stack[-1]]: + if nums2[stack[-1]] in nums1: + index = nums1.index(nums2[stack[-1]]) + result[index]=nums2[i] + stack.pop() + stack.append(i) + return result +``` +