Search⌘ K
AI Features

Solution: Maximum Swap

Solution: Maximum Swap challenges you to rearrange the digits of a nonnegative integer by making at most one swap, then return the largest number possible.

Statement

Given an integer num, return the maximum number that can be formed by swapping at most two digits once.

Constraints:

  • 0≤0 \leq num ≤105\leq 10^5 ...