java.lang.Object
g0501_0600.s0556_next_greater_element_iii.Solution

public class Solution extends Object
556 - Next Greater Element III.<p>Medium</p> <p>Given a positive integer <code>n</code>, find <em>the smallest integer which has exactly the same digits existing in the integer</em> <code>n</code> <em>and is greater in value than</em> <code>n</code>. If no such positive integer exists, return <code>-1</code>.</p> <p><strong>Note</strong> that the returned integer should fit in <strong>32-bit integer</strong> , if there is a valid answer but it does not fit in <strong>32-bit integer</strong> , return <code>-1</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 12</p> <p><strong>Output:</strong> 21</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 21</p> <p><strong>Output:</strong> -1</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 2<sup>31</sup> - 1</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • nextGreaterElement

      public int nextGreaterElement(int n)