利用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;
}
};
利用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
网友评论