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 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.
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的更多相关文章
- 【LeetCode】791. Custom Sort String 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 按顺序构造字符串 排序 日期 题目地址:https: ...
- 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 ...
- 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 ...
- 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 ...
- 791. Custom Sort String - LeetCode
Question 791. Custom Sort String Solution 题目大意:给你字符的顺序,让你排序另一个字符串. 思路: 输入参数如下: S = "cba" T ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
- LeetCode Weekly Contest 23
LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...
- LeetCode Weekly Contest
链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...
随机推荐
- ACM学习历程—51NOD1028 大数乘法V2(FFT)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...
- bzoj 2007 海拔 —— 最短路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2007 最后一定是起点周围一片0,终点周围一片1: 所以建出图来跑最短路即可. 代码如下: # ...
- asp.net分页asp.net无刷新分页高效率分页
项目中经常会用到分页的功能类似的项目做过无数个了,今个把自己常用的分页代码分享一下. 首先说说服务端处理的代码: 下面代码中重点是分页的sql语句的写法,其中的参数@n是当前的页码,总的来说本服务端主 ...
- MongoDB优化之三:如何排查MongoDB CPU利用率高的问题
遇到这个问题,99.9999% 的可能性是「用户使用上不合理导致」,本文主要介绍从应用的角度如何排查 MongoDB CPU 利用率高的问题. Step1: 分析数据库正在执行的请求 用户可以通过 M ...
- netty中的EventLoop和EventLoopGroup
Netty框架的主要线程就是I/O线程,线程模型设计的好坏,决定了系统的吞吐量.并发性和安全性等架构质量属性. 一.Netty的线程模型 在讨论Netty线程模型时候,一般首先会想到的是经典的Reac ...
- 四 Synchronized
首先,一个问题:一个boolean成员变量,一个方法赋值,一个方法读值,多线程环境下,需要同步吗? 如果用同步的话,读也要用synchroized修饰,因为可见性的问题 需要同步,或者用volatil ...
- windows 创建和调用 动态库,静态库
windows创建和调用静态库 // MathFuncsLib.h namespace MathFuncs { class MyMathFuncs { public: // Returns a + b ...
- SQL中top使用方法
转自:https://www.cnblogs.com/wang7/archive/2012/07/09/2582891.html 1. 在编写程序中,我们可能遇到诸如查询最热门的5篇文章或返回满足条件 ...
- commons-configuration读取配置文件
关键工具类: import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.con ...
- 菜鸟攻城狮1(JAVA程序设计)
1.JAVA是一个完整的平台,有一个庞大的库,提供了可重复利用的代码功能块,安全性,跨操作系统的可以移植性,自动垃圾回收机制 2.JAVA设计者白皮书:简单性.面向对象.网络技能.健壮性.安全性.体系 ...