Skip to content

Commit 08cad02

Browse files
authored
添加 0503.下一个更大元素II python3版本
添加 0503.下一个更大元素II python3版本
1 parent 9555e08 commit 08cad02

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,18 @@ public:
9797
Java:
9898
9999
Python:
100-
100+
```python3
101+
class Solution:
102+
def nextGreaterElements(self, nums: List[int]) -> List[int]:
103+
dp = [-1] * len(nums)
104+
stack = []
105+
for i in range(len(nums)*2):
106+
while(len(stack) != 0 and nums[i%len(nums)] > nums[stack[-1]]):
107+
dp[stack[-1]] = nums[i%len(nums)]
108+
stack.pop()
109+
stack.append(i%len(nums))
110+
return dp
111+
```
101112
Go:
102113

103114
JavaScript:

0 commit comments

Comments
 (0)