[Python 3] Solution and Explanation 🤲Sort The Digit!🤲
\n# [Python 3] Solution and Explanation \uD83E\uDD32Sort The Digit!\uD83E\uDD32\n\n\n## 1\uFE0F\u20E3 Main Idea\nWe seperate cases into two different way\n1. Nu
\n# [Python 3] Solution and Explanation \uD83E\uDD32Sort The Digit!\uD83E\uDD32\n\n\n## 1\uFE0F\u20E3 Main Idea\nWe seperate cases into two different way\n1. Num >= 0 : We sort every digit in increasing order, and make sure first index of digit not 0, so we find first not zero element and swap with 0. Finally we return number\n2. Num < 0 : We make num positive and sort in decreasing order, so we can find maximum num and then return - res\n\n## Complexity Analysis\n* Time: O(N log N) : Let *N* be the number of digits.\n* Space: O(1) \n\n## Code\n```\nclass Solution:\n    def smallestNumber(self, num: int) -> int:\n        if num >= 0:\n            numList = [int(c) for c in str(num)]\n            numList.sort()\n            if numList[0] == 0:\n                temp = 0\n                while temp < len(numList) - 1 and numList[temp] == 0:\n                    temp += 1\n                self.swap(temp, 0, numList)\n            res = 0\n            for num in numList:\n                res *= 10\n                res += num\n            return res\n        else:\n            num = abs(num)\n            numList = [int(c) for c in str(num)]\n            numList.sort(reverse = True)\n            res = 0\n            for num in numList:\n                res *= 10\n                res += num\n            return  - res\n    \n    def swap(self, i, j, array):\n        array[i], array[j] = array[j], array[i]\n```\n* See more 2022 Daily Challenge Solution : [GitHub](https://github.com/gcobs0834/2022-Daily-LeetCoding-Challenge-python3-)\n\n
[]