把数组排成最小的数
include
class Solution {
public:
string PrintMinNumber(vector<int> numbers) {
string res = "";
sort(numbers.begin(), numbers.end(), compare);
for(int i = 0; i<numbers.size(); i++)
{
res+= to_string(numbers[i]);
}
return res;
}
private:
static bool compare(int a, int b)
{
string A = "";
string B = "";
A = to_string(a);
B = to_string(b);</int>
string comA = A + B; //连接后的字符串1 string comB = B + A; //连接后的字符串2 return comA < comB; }
};