Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    670 - Maximum Swap.

    Medium

    You are given an integer num. You can swap two digits at most once to get the maximum valued number.

    Return the maximum valued number you can get.

    Example 1:

    Input: num = 2736

    Output: 7236

    Explanation: Swap the number 2 and the number 7.

    Example 2:

    Input: num = 9973

    Output: 9973

    Explanation: No swap.

    Constraints:

    • <code>0 <= num <= 10<sup>8</sup></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 maximumSwap(Integer num)
      • Methods inherited from class java.lang.Object

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