剑指OFFER----面试题45. 把数组排成最小的数

链接:https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/

代码:

class Solution {
public:
    static bool cmp(int a, int b) {
        auto as = to_string(a), bs = to_string(b);
        return as + bs < bs + as;
    }

    string minNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end(), cmp);
        string res = "";
        for (auto x: nums) res += to_string(x);
        return res;
    }
};

 

posted @ 2020-03-05 14:14  景云ⁿ  阅读(129)  评论(0编辑  收藏  举报