Beat 100% C++ Greedy
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nLet try some special te
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nLet try some special test case: 900, 1091, ... \n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n       string x = to_string(num);\n       char k;\n       for (char i : x){\n            if (i != \'9\'){\n                k = i;\n                break;\n            }\n       }\n       char f = x[0];\n       string mine = "", maxe ="";\n       for (char t : x){\n        if (t==k){\n            mine+="9";\n        }else mine+=t;\n        if (t == f){\n            maxe+="0";\n        }else maxe += t;\n       }\n\n\n       return abs(stoi(mine) - stoi(maxe));\n    }\n};\n```
['C++']