1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| class Solution:
def maxDiff(self, num: int) -> int:
a = b = str(num)
for digit in a:
if digit != "9":
a = a.replace(digit, "9")
break
if b[0] != "1":
b = b.replace(b[0], "1")
else:
for digit in b[1:]:
if digit not in "01":
b = b.replace(digit, "0")
break
return int(a) - int(b)
|