题解 | #把数组排成最小的数#

把数组排成最小的数

https://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993

class Solution {
public:
    string PrintMinNumber(vector<int> numbers) {
        vector<string> ns;
        for (auto &i: numbers) {
            ns.push_back(to_string(i));
        }
        sort(ns.begin(), ns.end(), [](string &a, string &b) {
            return a + b < b + a;
        });
        string res;
        for (auto &i: ns) res += i;
        return res;
    }
};

全部评论

相关推荐

想进开水团喝开水:哦 给我一个 就算你真拿到牛友也会为你开心的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务