Skip to content

Commit 82c2e08

Browse files
Merge pull request PawanJaiswal08#52 from SALONI-SHARMA-6/Custom-Sort-String
added Custom-Sort-String
2 parents 659774c + afd3708 commit 82c2e08

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Custom-Sort-String.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
string customSortString(string order, string s)
4+
{
5+
unordered_map<char,int>mp;
6+
for(auto it:s)
7+
mp[it]++;
8+
9+
string ans="";
10+
for(int i=0;i<order.size();++i)
11+
{
12+
auto x=find(s.begin(),s.end(),order[i]);
13+
if(x!=s.end())
14+
{
15+
while(mp[order[i]]--)
16+
ans+=order[i];
17+
}
18+
}
19+
20+
for(int i=0;i<s.size();++i)
21+
{
22+
auto x=find(order.begin(),order.end(),s[i]);
23+
if(x==order.end())
24+
ans+=s[i];
25+
}
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
 (0)