Problem
You are given an integer num
. Bob will sneakily remap one of the 10
possible digits(0
to 9
) to another digit.
Return the difference between the maximum and minimum value Bob can make by remap exactly one digit in num
.
Bob can remap a digit to it self.(not change)
Resulting number after remapping can contain leading zeros.
Intuition
Consider the number 11891
, Bob can remap 1
to 9
to obtain the max 99899
, and remap 1
to 0
to obtain the min 00890
.
Consider the number 99919
, Bob can remap 1
to 9
to obtain the max 99999
, and remap 9
to 0
to obtain the min 00010
.
Hence we can observe that remap the first non-9 digit to 9
to yield the max value. And replace the first digit to 0
to yield the min value.
COOOOOOOOOOOOODING
1 | class Solution{ |