🐍 Super simple Python3 🌟 | EASY, short and sweet 🍫 | O(1) TC and SC
Intuition\nWe will switch the number over to string to make use of python\'s easy string replace. \n\n# Approach\nFor minimal value, always replace the first di
# Intuition\nWe will switch the number over to string to make use of python\'s easy string replace. \n\n# Approach\nFor minimal value, always replace the first digit\'s all occurances with \'0\'s.\n\nFor maximal value, replace the first non-\'9\' digit with \'9\'.\n\n# Complexity\nThe lenght of `s` is `log(num, 10)`. As per the problem statement, `1 <= num <= 10^8`, so `log(num, 10) <= 8`.\n- Time complexity: `O(log num)`, which is constant `O(1)`.\n\n- Space complexity: `O(1)` Same as TC, because we allocate space for the string `s`.\n\n# Code\n```\nclass Solution:\n    def minMaxDifference(self, num: int) -> int:\n        s = str(num)\n        v_min = int(s.replace(s[0], \'0\'))\n        for c in s:\n            if c != \'9\':\n                s = s.replace(c, \'9\')\n                break\n        v_max = int(s)\n        return v_max - v_min\n```
['Math', 'String', 'Python3']