forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1432.java
More file actions
25 lines (24 loc) · 727 Bytes
/
1432.java
File metadata and controls
25 lines (24 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
public int maxDiff(int num) {
String a = Integer.toString(num), b = a;
for (int i = 0; i < a.length(); i++) {
char digit = a.charAt(i);
if (digit != '9') {
a = a.replace(digit, '9');
break;
}
}
if (b.charAt(0) != '1') {
b = b.replace(b.charAt(0), '1');
} else {
for (int i = 1; i < b.length(); i++) {
char bi = b.charAt(i);
if (bi != '0' && bi != '1') {
b = b.replace(bi, '0');
break;
}
}
}
return Integer.parseInt(a) - Integer.parseInt(b);
}
}