题意
把数组排成最小的数
方法
排序
代码
class Solution {
public:
static bool cmp(int a, int b){
string as = to_string(a), bs = to_string(b);
return as + bs < bs + as;
}
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,res,45,offer,bs
From: https://www.cnblogs.com/Figure_at_a_Window/p/17020519.html