Easy to understand JAVA solution with sorting
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlogn) because of .sort() method\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public long smallestNumber(long num) {\n\n        String digits = String.valueOf(Math.abs(num));\n        char[] numStr = digits.toCharArray();\n        Arrays.sort(numStr);\n        \n        //when num is +ve and the after sorting first digit is 0 need to swap then\n        if(num >= 0 && numStr[0] == \'0\'){\n           int i = 1;\n           while(i < numStr.length){\n             if(numStr[i] != \'0\'){\n              // swap number without taking extra varaible\n                numStr[0] ^=  numStr[i];\n                numStr[i] ^=  numStr[0];\n                numStr[0] ^=  numStr[i];\n                break;\n             }\n               i++;\n            }\n        }\n        \n        //make a String builder of the char ARRAy\n        StringBuilder sb = new StringBuilder(new String(numStr));\n\n        // if num is -ve then out - in front\n        num = num < 0 ? -Long.parseLong(sb.reverse().toString()) : Long.parseLong(sb.toString());\n\n        return num;\n    }\n}\n```
['Java']