2566. Maximum Difference by Remapping a Digit
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def minMaxDifference(self, num: int) -> int:
        s = str(num)
        
        # Calculate maximum value
        max_digit = next((x for x in s if x != '9'), None)
        max_num = int(s.replace(max_digit, '9')) if max_digit else num
        
        # Calculate minimum value
        min_num = int(s.replace(s[0], '0'))  # Replace first digit with '0'
        if min_num == 0 and s[0] == '9':  # Special case for leading zeros
            min_num = int(s.replace('9', '0'))  # Replace all '9' with '0'
        
        # Return the difference
        return max_num - min_num

```
['Python3']