剑指 Offer 45. 把数组排成最小的数https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/
先将 整型数组 转成 字符串数组
然后进行自定义的排序,排序规则为 拼接后字符串较小者在前
排序完成后,结果数组即为所求字符串,将数组拼接成一个字符串即可
string minNumber(vector<int>& nums) {
int n = nums.size();
vector<string> strs(n);
for (int i = 0; i < n; ++i)
{
strs[i] = to_string(nums[i]);
}
sort(strs.begin(), strs.end(), [](const string& a, const string& b) {
return (a + b) < (b + a);
});
return accumulate(strs.begin(), strs.end(), string());
}