2ms || C++ || O(n) || COUNT DIGITS
\nclass Solution\n{\npublic:\n    long long smallestNumber(long long num)\n    {\n        if (!num)\n            return 0;\n        bool a = (num < 0);\n       
```\nclass Solution\n{\npublic:\n    long long smallestNumber(long long num)\n    {\n        if (!num)\n            return 0;\n        bool a = (num < 0);\n        num = abs(num);\n        vector<int> v(10, 0);\n        while (num)\n        {\n            v[num % 10]++;\n            num /= 10;\n        }\n        num = 0;\n        int i = 1;\n        if (!a)\n        {\n            if (v[0])\n            {\n                while (v[i] == 0)\n                {\n                    i++;\n                }\n                num = i;\n                v[i]--;\n                while (v[0]--)\n                {\n                    num = num * 10;\n                }\n            }\n            else\n            {\n                i = 1;\n            }\n            for (; i < 10; i++)\n            {\n                while (v[i]--)\n                {\n                    num = num * 10 + i;\n                }\n            }\n            return num;\n        }\n        else\n        {\n\n            for (i = 9; i >= 0; i--)\n            {\n                while (v[i]--)\n                {\n                    num = num * 10 + i;\n                }\n            }\n            return -num;\n        }\n    }\n};\n```
['C', 'Sorting', 'C++']