C++ || Easy
\n\n# Code\n\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        string str = to_string(num);\n        int len = str.length();\n        cha
\n\n# Code\n```\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        string str = to_string(num);\n        int len = str.length();\n        char dig;\n        int index=-1;\n        \n        //searching first index with non \'9\'\n        for(int i=0;i<len;i++){\n            if(str[i] != \'9\'){\n                dig=str[i];\n                index=i;\n                break;\n            }\n        }\n        \n        int small,big;\n        string sm=str,bi=str;\n        \n        //swapping value to 9 in whole digit to get big number\n        if(index != -1)\n        {\n            for(int i=0;i<len;i++){\n                if(str[index] == str[i]){\n                    bi[i]=\'9\';\n                }\n            }\n        }\n        \n        //swapping all occurrences of 0th index to \'0\'\n        //to get smaller number\n        for(int i=0;i<len;i++){\n            if(str[0] == sm[i]){\n                sm[i]=\'0\';\n            }\n        }\n        int diff = stoi(bi)-stoi(sm);\n        return diff;\n    }\n};\n```
['C++']