C++ Easiest solution
\n\n# Complexity\n- Time complexity:O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(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:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        string str=to_string(num);\n        int max,min;\n       string temp=str;\n       int n=str.size();\n       int i=0;\n         while(str[i]==\'9\')\n        i++;\n      char c=str[i];\n        \n        for(auto &ch: temp)\n        {\n            if(ch==c)\n            ch=\'9\';\n        }\n        max=stoi(temp);\n        temp=str;\n      \n        c=str[0];\n        for(auto &ch: str)\n        {\n           if(ch==c)\n            ch=\'0\';\n        }\n     min=stoi(str);\n     cout<<"max="<<max<<" "<<"min="<<min<<endl;\n        return max-min;\n    }\n};\n```
['C++']