0ms 100% time beats 99.53 memory beats || beginner friendly approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        string a = to_string(num);\n        int i = 0;\n        long long ans = 0;\n        if(num==0)\n        return 0;\n        if(num>=0) {\n        sort(a.begin(),a.end());\n        if(a[0]==\'0\'){\n            while(i<a.length()) {\n                if(a[i]!=\'0\')\n                break;\n                i++;\n            }\n            swap(a[0],a[i]);\n        }\n        int start = 0;\n        while(start<a.length()) {\n            int num = a[start] - \'0\';\n            ans = (ans*10) + num;\n            start++;\n        }\n        }\n        else{\n            sort(a.begin(),a.end(),greater<int> ());\n            string b = "-";\n            for(int i = 0; i<a.length()-1; i++ ) {\n                b+=a[i];\n            }\n            a = b;\n            int start = 1;\n            while(start<a.length()) {\n                int num = a[start] - \'0\';\n                ans = (ans*10) + num;\n                start++;\n            }\n            ans = ans * -1;\n        }\n\n        return ans;\n    }\n};\n```
['C++']