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

Commit480939a

Browse files
authored
更新0496.下一个更大元素I.md Python3版本
1 parentde4e13f commit480939a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
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+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp