The longest solution that makes you feel related
Intuition
Find length of num, without convert it to string, because why we need to use a built in function for that, right? (I'm dumb)
Find the first digit that
# Intuition
- Find length of num, without convert it to string, because why we need to use a built in function for that, right? (I'm dumb)
- Find the first digit that not 9
- Loop through each digit of num and build it back to max value and min value
- Return max value - min value

# Complexity
- Time complexity:
$$O(3N)$$ because we loop though num's digits 3 times for nothing

- Space complexity:
A lot, I don't know, please help me calculate this

# Code
```python3 []
class Solution:
    def minMaxDifference(self, num: int) -> int:
        def getLengthNum(num: int, length: int) -> int:
            if num == 0:
                return length
            
            length += 1
            return getLengthNum(num // 10, length)
        
        def getChangeDigit(num: int, length: int) -> int:
            change = 0
            for i in range(length):
                p = 10 ** (length - i - 1)
                change = num // p
                num = num % p
                if change != 9:
                    break
            return change
                
        length = getLengthNum(num, 0)
        change = getChangeDigit(num, length)
        first = num // 10 ** (length - 1)
        i = 0
        maxv = 0
        minv = 0

        while i < length:
            p = 10 ** (length - i - 1)
            cur_first = num // p
            v = cur_first * p

            if cur_first == change:
                maxv += 9 * p
            else:
                maxv += v

            if cur_first != first:
                minv += v

            i += 1
            num %= p

        return maxv - minv
```
['Python3']