#670

Maximum Swap

specialist · 840 · lc medium +31 · verified · 52% accepted · 4,281 likes · top 42%

Description

Given an integer num, you may perform at most one swap of two of its digits. Return the largest possible integer that can be formed by this single swap.

Example 1:

Input: num = 2736
Output: 7236
Explanation: Swap the number 2 and the number 7.

Example 2:

Input: num = 9973
Output: 9973
Explanation: No swap.

Code

1
2
3