C++,代码简洁,自定义排序规则

拼接所有的字符串产生字典序最小的字符串

http://www.nowcoder.com/practice/f1f6a1a1b6f6409b944f869dc8fd3381

string minString(vector<string>& strs) {
        // write code here
        sort(strs.begin(), strs.end(), [](const string &a,const string& b){
            return (a+b)<(b+a);
        });
        string res;
        for (const auto& str : strs) {
            res += str;
        }
        return res;
    }
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 13:05
点赞 评论 收藏
分享
码农索隆:有点耳熟,你们是我教过最差的一届
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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