2566. Maximum Difference by Remapping a Digit

1 min read

class Solution:
def minMaxDifference(self, num: int) -> int:
snum = str(num)
maxNum = minNum = snum
for e in str(num):
if int(e) < 9 and maxNum == snum:
maxNum = snum.replace(e, "9")
if int(e) > 0 and minNum == snum:
minNum = snum.replace(e, "0")
return int(maxNum) - int(minNum)
0
Subscribe to my newsletter
Read articles from Tapan Rachchh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
