556. Next Greater Element III Medium

@problem@discussion
#Math#Two Pointers#String



1/**
2 * [556] Next Greater Element III
3 *
4 * Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1.
5 * Note that the returned integer should fit in 32-bit integer, if there is a valid answer but it does not fit in 32-bit integer, return -1.
6 *  
7 * Example 1:
8 * Input: n = 12
9 * Output: 21
10 * Example 2:
11 * Input: n = 21
12 * Output: -1
13 *  
14 * Constraints:
15 * 
16 * 	1 <= n <= 2^31 - 1
17 * 
18 */
19pub struct Solution {}
20
21// problem: https://leetcode.com/problems/next-greater-element-iii/
22// discuss: https://leetcode.com/problems/next-greater-element-iii/discuss/?currentPage=1&orderBy=most_votes&query=
23
24// submission codes start here
25
26impl Solution {
27    pub fn next_greater_element(n: i32) -> i32 {
28        0
29    }
30}
31
32// submission codes end
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn test_556() {
40    }
41}
42


Back
© 2025 bowen.ge All Rights Reserved.