791. Custom Sort String
S and T are strings composed of lowercase letters. In S, no letter occurs more than once.
S was sorted in some custom order previously. We want to permute the characters of T so that they match the order that S was sorted. More specifically, if x occurs before y in S, then x should occur before y in the returned string.
Return any permutation of T (as a string) that satisfies this property.
Example :
Input:
S = "cba"
T = "abcd"
Output: "cbad"
Explanation:
"a", "b", "c" appear in S, so the order of "a", "b", "c" should be "c", "b", and "a".
Since "d" does not appear in S, it can be at any position in T. "dcba", "cdba", "cbda" are also valid outputs.
Note:
Shas length at most26, and no character is repeated inS.Thas length at most200.SandTconsist of lowercase letters only.
将T按S中出现的字母顺序排序
C++(4ms):
class Solution {
public:
string customSortString(string S, string T) {
sort(T.begin() , T.end() , [&](char a , char b){
return S.find(a) < S.find(b) ;
}) ;
return T ;
}
};
791. Custom Sort String的更多相关文章
- 791. Custom Sort String - LeetCode
Question 791. Custom Sort String Solution 题目大意:给你字符的顺序,让你排序另一个字符串. 思路: 输入参数如下: S = "cba" T ...
- LeetCode 791. Custom Sort String
题目链接:https://leetcode.com/problems/custom-sort-string/description/ S and T are strings composed of l ...
- 791. Custom Sort String字符串保持字母一样,位置可以变
[抄题]: S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S wa ...
- [leetcode]791. Custom Sort String自定义排序字符串
S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...
- 【LeetCode】791. Custom Sort String 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 按顺序构造字符串 排序 日期 题目地址:https: ...
- [LeetCode] Custom Sort String 自定义排序的字符串
S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...
- [Swift]LeetCode791. 自定义字符串排序 | Custom Sort String
S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...
- 73th LeetCode Weekly Contest Custom Sort String
S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...
- [Javascript] Use a custom sort function on an Array in Javascript
Sorting in Javascript with sort uses lexical sorting by default, which means it will sort in alphabe ...
随机推荐
- NOIP2017结束了
NOIP 2017 两天T1总分80 D1T3爆零 学军数据255 洛谷数据270 大概连1=都没有吧 没有预料到的结果 想了很久 最后只能选择接受 看完成绩单 高二爷们也许只剩下CYC LLQ ZS ...
- Codeforces 932.F Escape Through Leaf
F. Escape Through Leaf time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- poj2549 Sumsets
Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11886 Accepted: 3273 Descript ...
- idea plugin 插件开发之检测文件修改
实现 ApplicationComponent,BulkFileListener 接口,当然由于是 ApplicationComponent,因此需要在 plugin.xml 加上相关配置. plug ...
- PHP_INT_SIZE
PHP_INT_SIZE:表示整数integer值的字长 PHP_INT_MAX:表示整数integer值的最大值 注: 输出下32位中PHP_INT_SIZE:4,PHP_INT_MAX:21474 ...
- [机器学习]-PCA数据降维:从代码到原理的深入解析
&*&:2017/6/16update,最近几天发现阅读这篇文章的朋友比较多,自己阅读发现,部分内容出现了问题,进行了更新. 一.什么是PCA:摘用一下百度百科的解释 PCA(Prin ...
- Grass is Green
Root 3719 - Grass is Green Time limit: 3.000 seconds This year exactly n <tex2html_verbatim_ma ...
- DHTML Object Model&DHTML&DOM
DHTML Object Model:DHTML对象模型,利用DHTML Object Model可以单独操作页面上的对象,每个HTML标记通过它的ID和NAME属性被操纵,每个对象都具有自己的属性. ...
- c++ poco 使用mysql中文乱码问题
poco 是c++ 一个比较好的库,现在正在学习使用它,碰到一些问题记录在此. poco版本:poco-1.46-all ,带有数据库的支持模块 操作系统:ubuntu 1.使用poco的MySQL模 ...
- 【BZOJ2882】【字符串的最小表示】工艺
题目描述 小敏和小燕是一对好朋友. 他们正在玩一种神奇的游戏,叫Minecraft. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工艺品最左边的方 ...