剑指 Offer 45. 把数组排成最小的数 - 力扣(LeetCode)
类似题:LeetCode第 179 题:最大数(C++)_zj-博客
class Solution {
public:
string minNumber(vector<int>& nums) {
vector<string> s;
for(const auto &num : nums) s.push_back(to_string(num));
sort(s.begin(), s.end(), [](const string &s1, const string &s2){return s1+s2 < s2+s1;});
return accumulate(s.begin(), s.end(), string());
}
};