We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 59c49a0 + 36590ce commit fda3692Copy full SHA for fda3692
2566. Maximum Difference by Remapping a Digit
@@ -0,0 +1,28 @@
1
+class Solution {
2
+public:
3
+ int minMaxDifference(int num) {
4
+ string s = to_string(num);
5
+
6
+ string s_max = s;
7
+ for (char c : s) {
8
+ if (c != '9') {
9
+ for (char &ch : s_max) {
10
+ if (ch == c) ch = '9';
11
+ }
12
+ break;
13
14
15
16
+ string s_min = s;
17
18
+ if (c != '0') {
19
+ for (char &ch : s_min) {
20
+ if (ch == c) ch = '0';
21
22
23
24
25
26
+ return stoi(s_max) - stoi(s_min);
27
28
+};
0 commit comments