mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
添加 503.下一个更大元素II Java方法
This commit is contained in:
@ -95,7 +95,23 @@ public:
|
|||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
|
||||||
Java:
|
Java:
|
||||||
|
```java
|
||||||
|
class Solution {
|
||||||
|
public int[] nextGreaterElements(int[] nums) {
|
||||||
|
int[] res = new int[nums.length];
|
||||||
|
Arrays.fill(res, -1);
|
||||||
|
Stack<Integer> 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:
|
Python:
|
||||||
```python3
|
```python3
|
||||||
class Solution:
|
class Solution:
|
||||||
|
Reference in New Issue
Block a user