利用了STL,思路易懂,但是如果舍弃STL实现有点难度
class Solution {
public:
string PrintMinNumber(vector<int> numbers) {
std::string res;
if (numbers.empty()) {
return res;
}
std::sort(numbers.begin(), numbers.end(), [](int a, int b) -> bool {return std::to_string(a) + std::to_string(b) < std::to_string(b) + std::to_string(a);});
for (int i = 0; i < numbers.size(); ++i) {
res += std::to_string(numbers[i]);
}
return res;
}
};