JavaScript | TC O(n) | SC O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\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```\n/**\n * @param {number} num\n * @return {number}\n */\nvar minMaxDifference = function(num) {\n    let str = num.toString();\n    let d1 = \'9\', d2 = \'0\';\n    let max = \'\', min = \'\';\n    \n    for (let i = 0; i < str.length; i++) {\n        if (d1 === \'9\' && str[i] !== \'9\') {\n            d1 = str[i];\n        }\n        \n        if (d1 === str[i]) {\n            max += \'9\';\n        } else {\n            max += str[i];\n        }\n        \n        if (d2 === \'0\' && str[i] !== \'0\') {\n            d2 = str[i];\n        }\n        \n        if (d2 === str[i]) {\n            min += \'0\';\n        } else {\n            min += str[i];\n        }        \n    }\n    \n    return Number(max) - Number(min);\n};\n```
['JavaScript']