|
| 1 | +<h2><a href="https://leetcode.com/problems/maximum-69-number">Maximum 69 Number</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p> |
| 2 | + |
| 3 | +<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> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> num = 9669 |
| 10 | +<strong>Output:</strong> 9969 |
| 11 | +<strong>Explanation:</strong> |
| 12 | +Changing the first digit results in 6669. |
| 13 | +Changing the second digit results in 9969. |
| 14 | +Changing the third digit results in 9699. |
| 15 | +Changing the fourth digit results in 9666. |
| 16 | +The maximum number is 9969. |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong class="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>Input:</strong> num = 9996 |
| 23 | +<strong>Output:</strong> 9999 |
| 24 | +<strong>Explanation:</strong> Changing the last digit 6 to 9 results in the maximum number. |
| 25 | +</pre> |
| 26 | + |
| 27 | +<p><strong class="example">Example 3:</strong></p> |
| 28 | + |
| 29 | +<pre> |
| 30 | +<strong>Input:</strong> num = 9999 |
| 31 | +<strong>Output:</strong> 9999 |
| 32 | +<strong>Explanation:</strong> It is better not to apply any change. |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>1 <= num <= 10<sup>4</sup></code></li> |
| 40 | + <li><code>num</code> consists of only <code>6</code> and <code>9</code> digits.</li> |
| 41 | +</ul> |
0 commit comments