把数组排成最小的数

class Solution {
public:
    static bool cmp(int a,int b)
    {
        string as=to_string(a),bs=to_string(b);
        return as+bs<bs+as;
    }
    string printMinNumber(vector<int>& nums) {
       sort(nums.begin(),nums.end(),cmp);
       string res;
       for(auto i:nums) res+=to_string(i);
       return res;
    }
};
posted @ 2023-04-23 15:46  穿过雾的阴霾  阅读(13)  评论(0)    收藏  举报