O(n) time and space, Straight Forward Approach
Intuition\n Describe your first thoughts on how to solve this problem. \nJust change first num thats not 9 for the max and not 0 for the min\n# Approach\n Descr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nJust change first num thats not 9 for the max and not 0 for the min\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSet 2 variable called Max_Num and Min_Num initialized them to an array where each element in the array is a string of 1 digit\nset anothe var digit_picked to None and then while looping throught the array of digits if we already picked a number we look at the current num in the array if it is equal to the number that we picked we change it to \'9\' or \'0\' depending on if we are trying to find the min or max at the end of the each for loop we convert the changed string back to and int and at the end of the min loop we subtract Min_Num from Max_Num and we return the difference\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n) where n is the amount of digits\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n) where n is the amount of digits\n# Code\n```python3 []\nclass Solution:\n    def minMaxDifference(self, num: int) -> int:\n        Max_Num = list(str(num))\n        Min_Num = list(str(num))\n        if len(Max_Num) == 1:\n            return 9\n        \n        digit_picked = None\n        for i in range(len(Max_Num)):\n            if digit_picked:\n                if Max_Num[i] == digit_picked:\n                    Max_Num[i] = \'9\'\n            elif Max_Num[i] < \'9\':\n                digit_picked = Max_Num[i]\n                Max_Num[i] = \'9\'\n        Max_Num = int("".join(Max_Num))\n        \n        digit_picked = None\n        for i in range(len(Min_Num)):\n            if digit_picked:\n                if Min_Num[i] == digit_picked:\n                    Min_Num[i] = \'0\'\n            elif Min_Num[i] != \'0\':\n                digit_picked = Min_Num[i]\n                Min_Num[i] = \'0\'\n        Min_Num = int("".join(Min_Num))\n        return Max_Num - Min_Num\n```
['Python3']