C++ || Simple, self explanatory || Sort Digits
\nclass Solution {\npublic:\n    long long smallestNumber(long long n) {\n        if(n==0)return 0;\n        long long ans;\n        // when n is negative arran
```\nclass Solution {\npublic:\n    long long smallestNumber(long long n) {\n        if(n==0)return 0;\n        long long ans;\n        // when n is negative arrange the digits of n in decreasing order\n        if(n<0)\n        {\n            n=-n;\n            string s=to_string(n);\n            sort(s.begin(),s.end(),greater<char>());\n            ans=stoll(s);\n                return -ans;\n        }\n        // if n is positive, sort in increasing order and find first non-zero digit, and then start the number with it \n        string s=to_string(n);\n        sort(s.begin(),s.end());\n        int i=0;\n        while(s[i]==\'0\')i++;\n        ans=s[i]-\'0\';\n        for(int j=0;j<s.size();j++)\n        {\n            if(j==i)continue;\n            ans=ans*10 + s[j]-\'0\';\n        }\n        return ans;\n    }\n};\n```\nIf it helps you, please do upvote it!!
['C', 'Sorting']