From 36590ce33118fa5e5339e5d967727be35f24d2f1 Mon Sep 17 00:00:00 2001 From: chayan das Date: Sat, 14 Jun 2025 11:30:38 +0530 Subject: [PATCH] Create 2566. Maximum Difference by Remapping a Digit --- 2566. Maximum Difference by Remapping a Digit | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 2566. Maximum Difference by Remapping a Digit diff --git a/2566. Maximum Difference by Remapping a Digit b/2566. Maximum Difference by Remapping a Digit new file mode 100644 index 0000000..444a9c5 --- /dev/null +++ b/2566. Maximum Difference by Remapping a Digit @@ -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); + } +};