Java solution | Sorting
Please Upvote !!!\n\nclass Solution {\n    public long smallestNumber(long num) {\n        \n        boolean isNegative = num < 0;\n        \n        num = Math
### Please Upvote !!!\n```\nclass Solution {\n    public long smallestNumber(long num) {\n        \n        boolean isNegative = num < 0;\n        \n        num = Math.abs(num);\n        \n        char[] arr = ("" + num).toCharArray();\n        \n        if (arr.length == 1) return Long.parseLong(String.valueOf(arr));\n        \n        long ans = 0;\n        Arrays.sort(arr);\n        \n        if (isNegative) {\n            String ansStr = "";\n            \n            for (int i = arr.length - 1; i >= 0; i--) {\n                ansStr += arr[i];\n            }\n            \n            ans = - Long.parseLong(ansStr);\n            \n        } else {\n            \n            if (arr[0] == \'0\'){\n                int i = 0;\n                while (arr[i] == \'0\') i++;\n\n                if (i < arr.length) {\n                    arr[0] = arr[i];\n                    arr[i] = \'0\';\n                }\n            }\n            \n            ans = Long.parseLong(String.valueOf(arr));\n        }\n        \n        return ans;\n    }\n}\n\n// TC: O(n * logn), SC: O(n)\n```
['Java']