Merge pull request #506 from jojoo15/patch-39

添加 0503.下一个更大元素II python3版本
This commit is contained in:
程序员Carl
2021-07-22 10:13:59 +08:00
committed by GitHub

View File

@ -97,7 +97,18 @@ public:
Java: Java:
Python: Python:
```python3
class Solution:
def nextGreaterElements(self, nums: List[int]) -> List[int]:
dp = [-1] * len(nums)
stack = []
for i in range(len(nums)*2):
while(len(stack) != 0 and nums[i%len(nums)] > nums[stack[-1]]):
dp[stack[-1]] = nums[i%len(nums)]
stack.pop()
stack.append(i%len(nums))
return dp
```
Go: Go:
JavaScript: JavaScript: