-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path791.cpp
More file actions
45 lines (41 loc) · 1.31 KB
/
791.cpp
File metadata and controls
45 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
string customSortString(string S, string T) {
multiset<char> a;
string res;
for (int i = 0; i < T.size(); i++) {
a.insert(T[i]);
}
for (int i = 0; i < S.size(); i++) {
int c = a.count(S[i]);
a.erase(S[i]);
for (int j = 0; j < c; j++) {
res.push_back(S[i]);
}
}
for (multiset<char>::iterator i = a.begin(); i != a.end(); ++i) {
res.push_back(*i);
}
return res;
}
};
__________________________________________________________________________________________________
sample 8340 kb submission
class Solution {
public:
string customSortString(string S, string T) {
size_t next_pos = 0;
for (const char c : S) {
for (size_t i = next_pos; i < T.size(); ++i) {
if (T[i] == c) {
std::swap(T[i], T[next_pos]);
++next_pos;
}
}
}
return T;
}
};
__________________________________________________________________________________________________