Largest Number After Digit Swaps by Parity
You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).
Return the largest possible value of num after any number of swaps.
Example 1
Input
num = 1234Output
3412By swapping digits only with digits of the same parity,
3412 is the largest possible number.Example 2
Input
num = 65875Output
87655By swapping digits only with digits of the same parity,
87655 is the largest possible number.Constraints
- 1 <= num <= 10^9