503. Next Greater Element II Medium
1/**
2 * [503] Next Greater Element II
3 *
4 * Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums.
5 * The next greater number of a number x is the first greater number to its traversing-order next in the array, which means you could search circularly to find its next greater number. If it doesn't exist, return -1 for this number.
6 *
7 * Example 1:
8 *
9 * Input: nums = [1,2,1]
10 * Output: [2,-1,2]
11 * Explanation: The first 1's next greater number is 2;
12 * The number 2 can't find next greater number.
13 * The second 1's next greater number needs to search circularly, which is also 2.
14 *
15 * Example 2:
16 *
17 * Input: nums = [1,2,3,4,3]
18 * Output: [2,3,4,-1,4]
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= nums.length <= 10^4
24 * -10^9 <= nums[i] <= 10^9
25 *
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/next-greater-element-ii/
30// discuss: https://leetcode.com/problems/next-greater-element-ii/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35 pub fn next_greater_elements(nums: Vec<i32>) -> Vec<i32> {
36 vec![]
37 }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_503() {
48 }
49}
50
Back
© 2025 bowen.ge All Rights Reserved.