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:

  • S has length at most 26, and no character is repeated in S.
  • T has length at most 200.
  • S and T consist of lowercase letters only.

S是一种字母的排序方式,现在让T按照S的排序方式再输出一次,在S没有出现的字母就随便排,S不会出现相同字母

首先T和S都出现的字母,我们按照S的字母出现位置放进新的字符串里,然后呢,没出现的放最后,再然后就是把空的位置去掉就好了。

 class Solution {
public:
map<char,int>Mp,mp;
string customSortString(string S, string T) {
string Str="";
string Ctr="";
int lens=S.length();
int lent=T.length();
for(int i=;i<max(lent,lens);i++){
Str+='#';
}
for(int i=;i<lens;i++){
Mp[S[i]]=i+;
}
for(int i=;i<lent;i++){
mp[T[i]]++;
if(Mp[T[i]]==){
continue;
}else{
Str[Mp[T[i]]-]=T[i];
}
}
//cout<<Str<<endl;
for(int i=;i<max(lent,lens);i++){
for(int j=;j<mp[Str[i]];j++){
Ctr+=Str[i];
}
}
for(int i=;i<lent;i++){
if(Mp[T[i]]==){
Ctr+=T[i];
}
}
return Ctr;
}
};

73th LeetCode Weekly Contest Custom Sort String的更多相关文章

  1. 【LeetCode】791. Custom Sort String 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 按顺序构造字符串 排序 日期 题目地址:https: ...

  2. 73th LeetCode Weekly Contest Rotated Digits

    X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...

  3. 73th LeetCode Weekly Contest Domino and Tromino Tiling

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  4. 73th LeetCode Weekly Contest Escape The Ghosts

    You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is(tar ...

  5. 791. Custom Sort String - LeetCode

    Question 791. Custom Sort String Solution 题目大意:给你字符的顺序,让你排序另一个字符串. 思路: 输入参数如下: S = "cba" T ...

  6. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  7. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  8. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  9. LeetCode Weekly Contest

    链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...

随机推荐

  1. 2017-2018-1 20179215《Linux内核原理与分析》第七周作业

    一.实验部分:分析Linux内核创建一个新进程的过程. [第一部分] 根据要求完成第一部分,步骤如下: 1. 首先进入虚拟机,打开终端,这命令行依次敲入以下命令: cd LinuxKernel    ...

  2. bzoj 4773: 负环 floyd

    题目: 对于边带权的有向图,找出一个点数最小的环,使得环上的边权和为负. 2 <= n <= 300. 题解: 我们可以考虑从小到大枚举答案. 然后每次枚举更大的答案的时候就从当前的较小的 ...

  3. bzoj 4504: K个串 可持久化线段树+堆

    题目: Description 兔子们在玩k个串的游戏.首先,它们拿出了一个长度为n的数字序列,选出其中的一 个连续子串,然后统计其子串中所有数字之和(注意这里重复出现的数字只被统计一次). 兔子们想 ...

  4. Chrome Developer Tools之内存分析

    可参考: Chrome Developer Tools之内存分析 http://www.kazaff.me/2014/01/26/chrome-developer-tools%E4%B9%8B%E5% ...

  5. bzoj 2395 Timeismoney —— 最小乘积生成树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2395 参考博客:https://www.cnblogs.com/autsky-jadek/p ...

  6. ABCD四个人说真话的概率都是1/3。假如A声称B否认C说D是说谎了,那么D说过的那句话真话的概率是多少

    ABCD四个人说真话的概率都是1/3.假如A声称B否认C说D是说谎了,那么D说过的那句话 真话的概率是多少 记"A声称B否认C说D说谎"为X,那么由贝叶斯公式,所求的 P(D真)P ...

  7. spring 4.0 注解数据验证1

    通常情况下,数据验证都分为前台验证,后台验证.并且前台JS验证是肯定有的,那么其实验证的错误信息根本不必通过后台传过去,哪怕就是想国际化,前台JS也能够胜任. 如果前台验证足够了,那么如果还有不正确的 ...

  8. 使用 Chrome Timeline 来优化页面性能

    使用 Chrome Timeline 来优化页面性能 有时候,我们就是会不由自主地写出一些低效的代码,严重影响页面运行的效率.或者我们接手的项目中,前人写出来的代码千奇百怪,比如为了一个 Canvas ...

  9. Session和cookie有什么区别?

    cookie是保存在客户端的信息,它只能保存String类型的,没有session安全,如果客户端禁用了cookie就不能够使用了 Cookie是客户端技术,程序把每个用户的数据以cookie的形式写 ...

  10. How to install Samba server on Ubuntu 12.04

    Part 1: Configuring anonymous share with samba server To install the samba package,enter the followi ...