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 not contain leading zeros.
Intuition
This problem is like to Leetcode2567, Yes…exactly the daily question in Leetcode yesterday. The only difference is that we canNOT have leading zeros today.
We need to consider how to get the minimum value. Is that replacing all first digit to 1? Apparently not, 11111
the min value should be 10000
.
Can we do the same thing in the way of finding the max value? Replace the first non-1 digit to 0? No…. which breaks the rule no leading zero..
Then maybe if the first digit is not 1
, we replace it to 1
. And for non-first digit, we change it to 0.
COOOOOOOOOOOOODING
1 | class Solution{ |