C++ || Brute Force || Easy approach
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(log(num))\n\n- Space complexity:O(log(num))\n\n# Code\n\nclass Solution {\npublic:\n 
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:$$O(log(num))$$\n\n- Space complexity:$$O(log(num))$$\n\n# Code\n```\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        string s="";\n        \n        map<char, int>m;\n        while(num){\n            s+=to_string(num%10);\n            num/=10;\n        }\n        //cout<<s<<endl;\n        for(int i=0; i<s.size(); i++){m[s[i]]++;}\n        reverse(s.begin(), s.end());\n        string s1=s, s2=s;\n        if(s[0]!=\'9\'){\n            char a=s[0];\n            \n            for(int i=0; i<s.size(); i++){\n                if(s[i]==a){\n                    s1[i]=\'9\';\n                    s2[i]=\'0\';\n                }\n            }\n        }\n        else{\n            //cout<<"here"<<endl;\n            char a=s[0], b=\'.\';\n            for(int i=0; i<s.size(); i++){\n                if(s[i]==a){\n                    s2[i]=\'0\';\n                }\n            }\n            for(int i=0; i<s.size(); i++){\n                if(s[i]!=\'9\'){\n                    b=s[i];\n                    break;\n                }\n            }\n            if(b!=\'.\'){\n                for(int i=0; i<s.size(); i++){\n                    if(s[i]==b){\n                        s1[i]=\'9\';\n                    }\n                }\n            }\n        }\n        int n1=0, n2=0;\n        for(int i=0; i<s1.size(); i++){\n            n1*=10;\n            n1+=(s1[i]-\'0\');\n        }\n        for(int i=0; i<s2.size(); i++){\n            n2*=10;\n            n2+=(s2[i]-\'0\');\n        }\n        cout<<n1<<" "<<s1<<" "<<n2<<" "<<s2<<endl;\n        return n1-n2;\n    }\n};\n```
['Math', 'String', 'C++']