剑指 Offer 45. 把数组排成最小的数
作者:互联网
class Solution {
public:
static bool cmp(int& a, int& b) {
string sa = to_string(a), sb = to_string(b);
return sa + sb < sb + sa;
}
string minNumber(vector<int>& nums) {
sort(nums.begin(), nums.end(), cmp);
string res;
for (int i = 0; i < nums.size(); i++)
res += to_string(nums[i]);
return res;
}
};
标签:排成,string,nums,int,Offer,45,res,sb,sa 来源: https://www.cnblogs.com/fxh0707/p/15084332.html