We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 0bbe229 + 7aae4f8 commit 9f23129Copy full SHA for 9f23129
problems/0503.下一个更大元素II.md
@@ -293,6 +293,28 @@ impl Solution {
293
}
294
```
295
296
+> 版本二:
297
+
298
+```rust
299
+impl Solution {
300
+ pub fn next_greater_elements(nums: Vec<i32>) -> Vec<i32> {
301
+ let (mut stack, mut res) = (vec![], vec![-1; nums.len()]);
302
303
+ for i in 0..nums.len() * 2 {
304
+ while let Some(&top) = stack.last() {
305
+ if nums[i % nums.len()] <= nums[top] {
306
+ break;
307
+ }
308
+ let saved_index = stack.pop().unwrap();
309
+ res[saved_index] = nums[i % nums.len()];
310
311
+ stack.push(i % nums.len());
312
313
314
+ res
315
316
+}
317
+```
318
319
<p align="center">
320
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
0 commit comments