mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
添加 0503.下一个更大元素II python3版本
添加 0503.下一个更大元素II python3版本
This commit is contained in:
@ -97,7 +97,18 @@ public:
|
||||
Java:
|
||||
|
||||
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:
|
||||
|
||||
JavaScript:
|
||||
|
Reference in New Issue
Block a user