[C++] 82% faster | Comments for Easy-Understanding ⚡
\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        //Edge case\n        if(num == 0) return 0;\n        //Checking if num is ne
```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        //Edge case\n        if(num == 0) return 0;\n        //Checking if num is negative or positive\n        bool flag = num < 0 ? true : false;\n        \n        string s = to_string(num);\n        \n        //For negative, digits will be sorted decreasing order -7605 -> 7650-\n        if(flag) sort(s.begin(), s.end(), greater<char>());\n        // else digits will be sorted increasing 310 -> 013\n        else sort(s.begin(), s.end());\n        \n        //If there are leading zeroes, swap it with recent proper digit from left\n        // 00559\n        // ^ ^\n        // | |\n        // ---\n        int i = 0;\n        while(s[i] == \'0\' && i<s.length()){\n            i++;\n        }\n        swap(s[i], s[0]);\n        \n        //Since there will be dash in end in negative after sorting, so we are simply \n        //removing it and we\'ll take care of that later.\n        if(flag) s.erase(s.begin() + s.length()-1, s.end());\n        \n        //Building number from string \n        long long finalval = 0;\n        for(auto x: s)\n            finalval = finalval*10 + (x - \'0\');\n        \n        //Handling negative case\n        return flag ? 0 - finalval : finalval;\n    }\n};\n```
['C']