要求:数组里的数拼接
思路:跟剑指45题类似
class Solution {
public:
string largestNumber(vector<int>& nums) {
vector<string> ans;
for(auto &num : nums)
ans.push_back(to_string(num));
sort(ans.begin(), ans.end(), [](const string& a, const string& b) {
return a + b > b + a;
});
string ret = "";
for(auto str : ans) ret += str;
if(ret[0]=='0')return "0";
return ret;
}
};