1class Solution {2public long smallestNumber(long num) {3if (num == 0) {4return 0;5}6boolean isNegative = num < 0;7num = num < 0 ? num * -1 : num;89char[] c = String.valueOf(num).toCharArray();10Arrays.sort(c);11String str;12if (!isNegative) {13int non = 0;14// if not negative we need to find out the first non-leading zero then swap with first zero15for (; non < c.length; non++) {16if (c[non] != '0') {17break;18}19}20char temp = c[non];21c[non] = c[0];22c[0] = temp;23str = new String(c);24} else {25str = new String(c);26StringBuilder sb = new StringBuilder(str);27str = "-".concat(sb.reverse().toString());28}29return Long.valueOf(str);30}31}