题解 | #最大数#
最大数
http://www.nowcoder.com/practice/fc897457408f4bbe9d3f87588f497729
排序题
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;
}
};
深信服公司福利 836人发布
查看12道真题和解析