这题居然是中等……直接排个序就行了。
轻微压行:
class Solution {
public:
static bool cmp(int &a,int &b){return to_string(a)+to_string(b)<to_string(b)+to_string(a);}
string printMinNumber(vector<int>& nums){string s="";sort(nums.begin(),nums.end(),cmp);for (auto x:nums) s+=to_string(x);return s;}
};
普通:
class Solution {
public:
static bool cmp(int &a,int &b){return to_string(a)+to_string(b)<to_string(b)+to_string(a);}
string printMinNumber(vector<int>& nums) {
string s="";
sort(nums.begin(),nums.end(),cmp);
for (auto x:nums) s+=to_string(x);
return s;
}
};