Python3 O(N log N) Solution with sorting (100.00% Runtime)
IntuitionApproach
Break down the num in to array of digits and sort them.
Rearrange them based on their sign and existence of leading zeros.
Complexity
Time com
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
![image.png](https://assets.leetcode.com/users/images/84846782-9454-4f4b-a3eb-26341af089e6_1740318542.522864.png)

# Approach
<!-- Describe your approach to solving the problem. -->
- Break down the num in to array of digits and sort them.
- Rearrange them based on their sign and existence of leading zeros.

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

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

# Code
If this solution is similar to yours or helpful, upvote me if you don't mind
```python3 []
class Solution:
    def smallestNumber(self, num: int) -> int:
        sign = 1 if num >= 0 else -1
        if sign < 0:
            num = -num
        arr = sorted([int(x) for x in str(num)])

        if len(arr) == 1:
            return sign * arr[0]
        
        if sign > 0:
            i = j = 0
            while arr[i] == 0:
                i += 1
            arr[i], arr[j] = arr[j], arr[i]
        else:
            arr = arr[::-1]

        return sign * int(''.join([str(x) for x in arr]))

```
['Array', 'Math', 'String', 'Greedy', 'Brainteaser', 'Sorting', 'Combinatorics', 'Python', 'Python3']