class Solution { static bool compare ( int a , int b ) { string str_a = to_string ( a ) + to_string ( b ); string str_b = to_string ( b ) + to_string ( a ); return str_a str_b ; } public : string largestNumber ( vector int nums ) { string r
class Solution {
static bool compare(int &a,int &b)
{
string str_a=to_string(a)+to_string(b);
string str_b=to_string(b)+to_string(a);
return str_a>str_b;
}
public:
string largestNumber(vector<int>& nums) {
string res;
if(nums.size()==0)return res;
sort(nums.begin(),nums.end(),compare);
for(int i=0;i<nums.size();i++)
{
res+=to_string(nums[i]);
//00输入例子
if(nums[0]==0)break;
}
return res;
}
};