Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions 2566. Maximum Difference by Remapping a Digit
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public:
int minMaxDifference(int num) {
string s = to_string(num);

string s_max = s;
for (char c : s) {
if (c != '9') {
for (char &ch : s_max) {
if (ch == c) ch = '9';
}
break;
}
}

string s_min = s;
for (char c : s) {
if (c != '0') {
for (char &ch : s_min) {
if (ch == c) ch = '0';
}
break;
}
}

return stoi(s_max) - stoi(s_min);
}
};
Loading