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 ...
随机推荐
- HihoCoder1664 01间隔方阵([Offer收割]编程练习赛40)(DP)
给定一个NxM的01矩阵,小Hi希望从中找到一个01间隔的子方阵,并且方阵的边长越大越好. 例如对于 0100100 1000101 0101010 1010101 0101010 在右下角有一个4x ...
- [HDU4652]Dice
vjudge 题意 \(m\)面骰子,求 1.连续出现\(n\)个相同的停止: 2.连续出现\(n\)个不同的停止 的期望投骰子次数. \(n,m ≤ 10^6\) sol 首先考虑一个转移式子吧. ...
- BestCoder Round #92 比赛记录
上午考完试后看到了晚上的BestCoder比赛,全机房都来参加 感觉压力好大啊QAQ,要被虐了. 7:00 比赛开始了,迅速点进了T1 大呼这好水啊!告诉了同桌怎么看中文题面 然后就开始码码码,4分1 ...
- 洛谷【P1104】生日(冒泡排序版)
题目传送门:https://www.luogu.org/problemnew/show/P1104 题目很简单,我主要是来讲冒泡排序的. 所谓冒泡排序,流程如下: 每次确定一个\(rk\)(从\(n\ ...
- Python xlrd、xlwt、xlutils修改Excel文件-OK
一.xlrd读取excel 这里介绍一个不错的包xlrs,可以工作在任何平台.这也就意味着你可以在Linux下读取Excel文件. 首先,打开workbook: import xlrdwb = ...
- vs2015解决fopen、fscanf 要求替换为fopen_s、fscanf_s的办法
在工程项目设置一下就行:项目属性 -- C/C++-- 预处理器 -- 预处理器定义,添加:_CRT_SECURE_NO_WARNINGS
- java web项目创建
https://www.cnblogs.com/kangjianwei101/p/5621738.html
- JVM体系结构之三:方法区之1
一.简介 方法区在JVM中也是一个非常重要的区域,它与堆一样,是被线程共享的区域.在方法区中,存储了每个类的信息(包括类的名称.方法信息.字段信息).静态变量.常量以及编译器编译后的代码等. 方法区( ...
- PopupWindow 从底部弹出窗体
第一步 : 初始化PopupWindow private void initPop() { if (view == null) { // 照片 view = View.inflate(Registe ...
- ViewPage+Fragment(仿微信切换带通知)
第一步 : 布局文件 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <Li ...