Sort || C++ || 100% Faster
To make a postive number smallest we just need to sort it in increasing order, but we need to remove the leading zeroes.\nAnd to make a negative number smallest
To make a postive number smallest we just need to sort it in increasing order, but we need to remove the leading zeroes.\nAnd to make a negative number smallest we just need to sort it in decreasing order.\n```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        if(num==0) return 0;\n        string s = to_string(num);\n        int neg = 0;\n        if(num<0) neg = 1;\n        if(neg==0) {\n            sort(s.begin(), s.end());\n        } else {\n            sort(s.begin(), s.end(), greater<int>());\n        }\n\t\t// we remove all leading zeroes from the front.\n        int zeroes = 0;\n        char val;\n        for(int i = 0; i < s.length(); i++) {\n            if(s[i] == \'0\') zeroes++;\n            else {\n                val = s[i];\n                break;\n            }\n        }\n        for(int i = 0; i <= zeroes; i++) {\n            if(i==0) s[i] = val;\n            else\n                s[i] = \'0\';\n        }\n        num = stoll(s);\n        if(neg == 1) num *= -1;\n        return num;\n    }\n};\n```
['Math', 'C', 'Sorting']