Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    556 - Next Greater Element III.

    Medium

    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.

    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.

    Example 1:

    Input: n = 12

    Output: 21

    Example 2:

    Input: n = 21

    Output: -1

    Constraints:

    • <code>1 <= n <= 2<sup>31</sup> - 1</code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer nextGreaterElement(Integer n)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait