100% run time and 75% space
IntuitionApproachComplexity
Time complexity:O(n)

Space complexity:O(1)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int minMaxDifference(int num) {
        string s = to_string(num);
        for (int i = 0; i < s.length(); i++){
            if (s[i] < '9'){
                for (int j = i + 1; j < s.length(); j++){
                    if (s[i] == s[j]){
                        s[j] = '9';
                    }
                }
                s[i] = '9';
                break;
            }
        }
        int max = stoi(s);
        s = to_string(num);
        for (int i = 0; i < s.length(); i++){
            if (s[i] > '0'){
                for (int j = i + 1; j < s.length(); j++){
                    if (s[i] == s[j]){
                        s[j] = '0';
                    }
                }
                s[i] = '0';
                break;
            }
        }
        return max - stoi(s);
    }
};
```
['Math', 'Greedy', 'C++']