Class Solution
java.lang.Object
g2201_2300.s2231_largest_number_after_digit_swaps_by_parity.Solution
2231 - Largest Number After Digit Swaps by Parity.<p>Easy</p>
<p>You are given a positive integer <code>num</code>. You may swap any two digits of <code>num</code> that have the same <strong>parity</strong> (i.e. both odd digits or both even digits).</p>
<p>Return <em>the <strong>largest</strong> possible value of</em> <code>num</code> <em>after <strong>any</strong> number of swaps.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> num = 1234</p>
<p><strong>Output:</strong> 3412</p>
<p><strong>Explanation:</strong> Swap the digit 3 with the digit 1, this results in the number 3214.</p>
<p>Swap the digit 2 with the digit 4, this results in the number 3412.</p>
<p>Note that there may be other sequences of swaps but it can be shown that 3412 is the largest possible number.</p>
<p>Also note that we may not swap the digit 4 with the digit 1 since they are of different parities.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> num = 65875</p>
<p><strong>Output:</strong> 87655</p>
<p><strong>Explanation:</strong> Swap the digit 8 with the digit 6, this results in the number 85675.</p>
<p>Swap the first digit 5 with the digit 7, this results in the number 87655.</p>
<p>Note that there may be other sequences of swaps but it can be shown that 87655 is the largest possible number.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= num <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
largestInteger
public int largestInteger(int num)
-