diff --git a/problems/0503.下一个更大元素II.md b/problems/0503.下一个更大元素II.md index 3980cb0e..34ade48e 100644 --- a/problems/0503.下一个更大元素II.md +++ b/problems/0503.下一个更大元素II.md @@ -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: