the 100 beats solution
IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
O(n)
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)
- Space complexity:
    O(n)

# Code
```javascript []
/**
 * @param {number} num
 * @return {number}
 */
var minMaxDifference = function (num) {
    let numStr = num.toString();
    let maxStr = numStr;
    let minStr = numStr;

    // Find the maximum number by replacing the first non-9 digit with 9
    for (let i = 0; i < numStr.length; i++) {
        if (numStr[i] !== '9') {
            maxStr = numStr.replace(new RegExp(numStr[i], 'g'), '9');
            break;
        }
    }

    // Find the minimum number by replacing all occurrences of the first digit with 0
    minStr = numStr.replace(new RegExp(numStr[0], 'g'), '0');

    let max = parseInt(maxStr);
    let min = parseInt(minStr);
    let dif = max - min;

    return dif;
};
```
['JavaScript']