Easy and Clear Solution , stoi ,to_string , C++
\n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:(1)\n Add your space complexity here, e.g. O(n) \n\n
\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        char c;\n        string str=to_string(num);\n        int n=str.size();\n        for(int i=0;i<n;i++){\n            if(str[i]!=\'9\'){\n                c=str[i];\n                break;\n            }\n        }\n        for(int i=0;i<n;i++){\n            if(str[i]==c){\n                str[i]=\'9\';\n            }\n        }\n        string st=to_string(num);\n        char d=st[0];\n        for(int i=0;i<n;i++){\n            if(st[i]==d){\n                st[i]=\'0\';\n            }\n        }\n        int a=stoi(str);\n        int b=stoi(st);\n        return a-b;\n    }\n};\n```
['C++']