题解 | #最大数#重写sort
最大数
http://www.nowcoder.com/practice/fc897457408f4bbe9d3f87588f497729
class Solution {
public:
static bool cmp(int a, int b){ //高位位置排
string s_a = to_string(a); // 组合数最大用string判断
string s_b = to_string(b);
return s_a+s_b > s_b+s_a;
}
string solve(vector<int>& nums) {
// write code here
string ans;
sort(nums.begin(), nums.end(), cmp);
if(nums[0]==0) return "0";
for(int i=0;i<nums.size();i++){
ans += to_string(nums[i]);
}
return ans;
}
};