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:
S
has length at most26
, and no character is repeated inS
.T
has length at most200
.S
andT
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的更多相关文章
- 【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 ...
随机推荐
- Poj 2350 Above Average(精度控制)
一.Description It is said that 90% of frosh expect to be above average in their class. You are to pro ...
- vijos1779国王游戏
描述 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这n位大臣排成一排,国王站在队伍的最前面.排好队后, ...
- HDUj2612(两个起点找到最近的目的地)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- C笔试题(一)
a和b两个整数,不用if, while, switch, for,>, <, >=, <=, ?:,求出两者的较大值. 答案: int func(int a, int b) { ...
- 大内存电脑在vbox安装linux报错
问题描述: 1.机器:Linux主机,特别是主机为大内存,比如: 4G内存的使用pae内核的Ubuntu系统的thinkpad电脑. 2.情况:使用VirtualBox安装Linux系统时,比如:通过 ...
- MySql数据库数据更新操作其高级应用
数据更新操作有3种:向表中添加数据.修改表中的数据和删除表中的数据. 用来演示的数据表用student.course.sc三个数据表,数据表具体内容在:PHP和MySql数据库,如何获取每个分类的记录 ...
- python 列表中 [[], [], []] 和 3*[[]]差异
问: What's the difference between "[[], [], []]" and "3*[[]]" ? 答: [[], [], []] m ...
- 通过sessionid提取这个用户在服务器中保存的session变量
- TMF SID中的角色模式
角色模式 Copyright © TeleManagement Forum 2013. All Rights Reserved. This document and translations of i ...
- [转]简短介绍 C# 6 的新特性
原文地址:http://www.oschina.net/translate/briefly-exploring-csharp-new-features 几周前我在不同的地方读到了有关C#6的一些新特性 ...