Stringify and Sort | Go
IntuitionMy first thought was to stringify the number and simply reverse it, but to prevent leading zeros I would have to do a little bit more string manipulati
# Intuition
My first thought was to stringify the number and simply reverse it, but to prevent leading zeros I would have to do a little bit more string manipulation before it would be ready to convert back to an `int`. 

# Approach
My approach is to first convert the `int` to a `string`, split it into a slice, and then sort it. From there, I count the number of zeros to find how much of the original slice I should retain as non-zero digits, and then I store the non-zero characters in a new slice.

There are two ways it can go from here:
**Positive**: If the number is positive, then I create a new slice with the first value of the non-zero character slice at position 0, then the string of zeros at position 1, and the remaining non-zero characters are unpacked into the slice. The slice is then joined into a string.
**Negative**: If the number is negative, then I reverse the non-zero characters and join them together (omitting the negative sign), and concatenate the zeros to the end of it. 

Once that process is handled, if the number was negative then I return the int value multiplied by negative 1. Otherwise, the value is returned as is.


# Complexity
- Time complexity: $$O(n)$$ The time complexity increases linearly with the number of digits.

- Space complexity: $$O(n)$$ The space complexity increases linearly with the number of digits

# Code
```golang []
func smallestNumber(num int64) int64 {
	if num == 0 {
		return 0
	}

	strNums := strings.Split(strconv.Itoa(int(num)), "")
	slices.Sort(strNums)

    var non0StrNums []string
zc:
	for i, n := range strNums {
		if n != "0" {
			non0StrNums = strNums[i:]
			break zc
		}
	}

    var strNum string
	if num < 0 {
		slices.Reverse(non0StrNums)
		strNum = strings.Join(non0StrNums[:len(non0StrNums)-1], "") + strings.Repeat("0", len(strNums)-len(non0StrNums))
	} else {
		newArr := append([]string{non0StrNums[0], strings.Repeat("0", len(strNums)-len(non0StrNums))}, non0StrNums[1:]...)
		strNum = strings.Join(newArr, "")
	}
    val, _ := strconv.ParseInt(strNum, 10, 64)
    if num < 0 {
        return val * -1
    }
    return val
}
```
['Go']