O(N) C++
\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        \n        string s = to_string(num);\n        unordered_map<char,int>map;\n 
```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        \n        string s = to_string(num);\n        unordered_map<char,int>map;\n        \n        for(auto &i : s) map[i]++;\n        \n        string t;\n        \n        if(num<0){\n            for(char i = \'9\';i>=\'0\';i--){\n                while(map[i]){\n                    t+=i;\n                    map[i]--;\n                }\n            }\n            return stoll(t) * -1;\n        }\n        \n        //if positive or 0\n        for(char i = \'1\';i<=\'9\';i++){\n            if(map[i]){                    \n                t+=i;\n                map[i]--;\n                break;\n            }\n        }\n        \n        for(char i = \'0\';i<=\'9\';i++){\n            while(map[i]){\n                t+=i;\n                map[i]--;\n            }\n        }\n        \n        return stoll(t);\n    }\n};\n```
['C']