美文网首页
Leetcode 791. 自定义字符串排序

Leetcode 791. 自定义字符串排序

作者: jun_hinokeso | 来源:发表于2018-08-24 14:58 被阅读0次

利用algorithm里的sort加上lambda表达式(捕获S),两行代码完成。

class Solution {
public:
    string customSortString(string S, string T) {
        sort(T.begin(), T.end(), [S](const char& l, const char& r){return (S.find(l) < S.find(r));});
        return T;
    }
};

相关文章

网友评论

      本文标题:Leetcode 791. 自定义字符串排序

      本文链接:https://www.haomeiwen.com/subject/cvnbiftx.html