Skip to content

Commit 6069046

Browse files
committed
Time: 0 ms (100%), Space: 8.2 MB (37.74%) - LeetHub
1 parent 6c60882 commit 6069046

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int minMaxDifference(int num) {
4+
string a = to_string(num);
5+
string b = a;
6+
char x = '9';
7+
8+
for (auto& i : a) {
9+
if (i != '9') {
10+
x = i;
11+
break;
12+
}
13+
}
14+
for (auto& i : a) if (i == x) i = '9';
15+
16+
x = b.front();
17+
for (auto& i : b) if (i == x) i = '0';
18+
19+
return stoi(a) - stoi(b);
20+
}
21+
};

0 commit comments

Comments
 (0)