Maximum Swap
Solution ApproachWas this helpful?
Medium•array•Expected: O(n) time, O(1) space
Problem
Given a non-negative integer, swap two digits at most once to get the maximum valued number.
Example 1:
Input: num = 2736
Output: 7236
Explanation: Swap digits 2 and 7.
Example 2:
Input: num = 9973
Output: 9973
Explanation: No swap needed — already the maximum.
Reference solution unlocks after your first submission
Loading...
