diff --git a/problems/0503.下一个更大元素II.md b/problems/0503.下一个更大元素II.md index 34ade48e..6e351f27 100644 --- a/problems/0503.下一个更大元素II.md +++ b/problems/0503.下一个更大元素II.md @@ -95,7 +95,23 @@ public: ## 其他语言版本 Java: +```java +class Solution { + public int[] nextGreaterElements(int[] nums) { + int[] res = new int[nums.length]; + Arrays.fill(res, -1); + Stack temp = new Stack<>(); + for (int i = 1; i < nums.length * 2; i++) { + while (!temp.isEmpty() && nums[temp.peek()] < nums[i % nums.length]) { + res[temp.pop()] = nums[i % nums.length]; + } + temp.add(i % nums.length); + } + return res; + } +} +``` Python: ```python3 class Solution: