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

Commit 95f1d8a

Browse files
Merge pull request youngyangyang04#2420 from 0zz10/patch-1
Update 0503.下一个更大元素II.md
2 parents b92898d + 68cdbdb commit 95f1d8a

File tree

1 file changed

+0
-21
lines changed

1 file changed

+0
-21
lines changed

‎problems/0503.下一个更大元素II.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ class Solution {
170170
### Python:
171171

172172
```python
173-
# 方法 1:
174173
class Solution:
175174
def nextGreaterElements(self, nums: List[int]) -> List[int]:
176175
dp = [-1] * len(nums)
@@ -181,26 +180,6 @@ class Solution:
181180
stack.pop()
182181
stack.append(i%len(nums))
183182
return dp
184-
185-
# 方法 2:
186-
class Solution:
187-
def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
188-
stack = []
189-
# 创建答案数组
190-
ans = [-1] * len(nums1)
191-
for i in range(len(nums2)):
192-
while len(stack) > 0 and nums2[i] > nums2[stack[-1]]:
193-
# 判断 num1 是否有 nums2[stack[-1]]。如果没有这个判断会出现指针异常
194-
if nums2[stack[-1]] in nums1:
195-
# 锁定 num1 检索的 index
196-
index = nums1.index(nums2[stack[-1]])
197-
# 更新答案数组
198-
ans[index] = nums2[i]
199-
# 弹出小元素
200-
# 这个代码一定要放在 if 外面。否则单调栈的逻辑就不成立了
201-
stack.pop()
202-
stack.append(i)
203-
return ans
204183
```
205184
### Go:
206185

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /