Skip to content

Maximum Swap

MediumGreedy
Decode it first. Clues, constraints, pattern and plan before any code.

You may swap two digits of the non-negative integer num at most once. Return the largest number you can get.

num = 2736  →  7236
num = 9973  →  9973   (already the largest, no swap)
num = 1993  →  9913

Constraints

  • 0 <= num <= 10^8