排序题
class Solution {
public:
/**
* 最大数
* @param nums int整型vector
* @return string字符串
*/
string solve(vector<int>& nums) {
// write code here
sort(nums.begin(), nums.end(), [](int a, int b){
return to_string(a) + to_string(b) > to_string(b) + to_string(a);
});
string str;
for(int x:nums){
str += to_string(x);
}
while(str.length() > 1 && str[0] == '0') str.erase(0, 1); //去掉前导0
return str;
}
}; 
京公网安备 11010502036488号