Class Solution

java.lang.Object
g1301_1400.s1323_maximum_69_number.Solution

public class Solution extends Object
1323 - Maximum 69 Number.<p>Easy</p> <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p> <p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code> <em>becomes</em> <code>9</code><em>, and</em> <code>9</code> <em>becomes</em> <code>6</code><em>)</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> num = 9669</p> <p><strong>Output:</strong> 9969</p> <p><strong>Explanation:</strong></p> <p>Changing the first digit results in 6669.</p> <p>Changing the second digit results in 9969.</p> <p>Changing the third digit results in 9699.</p> <p>Changing the fourth digit results in 9666.</p> <p>The maximum number is 9969.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> num = 9996</p> <p><strong>Output:</strong> 9999</p> <p><strong>Explanation:</strong> Changing the last digit 6 to 9 results in the maximum number.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> num = 9999</p> <p><strong>Output:</strong> 9999</p> <p><strong>Explanation:</strong> It is better not to apply any change.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= num <= 10<sup>4</sup></code></li> <li><code>num</code> consists of only <code>6</code> and <code>9</code> digits.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximum69Number

      public int maximum69Number(int num)