C++ || GREEDY || SORTING
```\nclass Solution {\npublic:\n    \n    long long solve(long long num, int sign){\n        long long ans =0;\n        vector store;\n        // if num is posi
```\nclass Solution {\npublic:\n    \n    long long solve(long long num, int sign){\n        long long ans =0;\n        vector<int> store;\n        // if num is positive\n        if(sign == 1){\n            int zr =0;\n            while(num){\n                int dig = num % 10;\n                if(dig == 0) zr++;\n                store.push_back(dig);\n                num /= 10;\n            }\n            \n            if(zr == 0)\n            { sort(store.begin(), store.end());\n               for(int ele : store){\n                   ans = ans * 10 + ele;\n               }\n                   \n            }\n                     \n            else{ sort(store.begin(), store.end());\n                  int i=0;\n                  while(store[i] == 0) i++;\n                  ans = ans * 10 + store[i];\n                  i++;\n                  while(zr--) ans = ans * 10 + 0;\n                  while(i < store.size()) ans = ans*10 + store[i++];\n            }\n          }\n\t\t  \n\t\t  // if num is negative\n        else{   num *= -1;\n                while(num){\n                int dig = num % 10;\n\n                store.push_back(dig);\n                num /= 10;\n            }\n               sort(store.begin(), store.end(), greater<int>());\n               for(int ele : store){\n                   ans = ans * 10 + ele;\n               }\n        }\n        \n         return ans;\n    } \n    \n    \n    \n    long long smallestNumber(long long num) {\n        long long sign = num > 0 ? 1 : -1;\n        long long ans;\n        // we will try to minimize\n        if(sign == 1){\n           ans = solve(num, 1);\n        }\n        // we will try to maximize\n        \n        else{  \n            ans = solve(num, -1);\n        }\n        \n        return sign > 0 ? sign * ans : sign * ans;\n    }\n};
['Greedy', 'C', 'Sorting']