Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita9344c2

Browse files
Merge pull requestyoungyangyang04#476 from lichun-chen/master
更新 0739. 每日温度.md Python3 版本代码
2 parents8249e35 +480939a commita9344c2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

‎problems/0496.下一个更大元素I.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,26 @@ public:
185185

186186
建议大家把情况一二三想清楚了,先写出版本一的代码,然后在其基础上在做精简!
187187

188+
##其他语言版本
189+
190+
Python:
191+
```python3
192+
classSolution:
193+
defnextGreaterElement(self,nums1: List[int],nums2: List[int]) -> List[int]:
194+
result= [-1]*len(nums1)
195+
stack= [0]
196+
for iinrange(1,len(nums2)):
197+
# 情况一情况二
198+
if nums2[i]<=nums2[stack[-1]]:
199+
stack.append(i)
200+
# 情况三
201+
else:
202+
whilelen(stack)!=0and nums2[i]>nums2[stack[-1]]:
203+
if nums2[stack[-1]]in nums1:
204+
index= nums1.index(nums2[stack[-1]])
205+
result[index]=nums2[i]
206+
stack.pop()
207+
stack.append(i)
208+
return result
209+
```
210+

‎problems/0739.每日温度.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,24 @@ Java:
211211
}
212212
```
213213
Python:
214-
214+
```Python3
215+
classSolution:
216+
defdailyTemperatures(self,temperatures: List[int]) -> List[int]:
217+
answer= [0]*len(temperatures)
218+
stack= [0]
219+
for iinrange(1,len(temperatures)):
220+
# 情况一和情况二
221+
if temperatures[i]<=temperatures[stack[-1]]:
222+
stack.append(i)
223+
# 情况三
224+
else:
225+
whilelen(stack)!=0and temperatures[i]>temperatures[stack[-1]]:
226+
answer[stack[-1]]=i-stack[-1]
227+
stack.pop()
228+
stack.append(i)
229+
230+
return answer
231+
```
215232
Go:
216233

217234
> 暴力法

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp