1
class Solution {
2
public:
3
vector<int> relativeSortArray(vector<int> &arr1, vector<int> &arr2) {
4
map<int, int> sk;
5
vector<int> res;
6
for (auto i : arr1) {
7
sk[i]++;
8
}
9
for (auto j : arr2) {
10
for (auto z : sk) {
11
if (z.first == j) {
12
int x = z.second;
13
for (int l = 0; l < x; l++) {
14
res.push_back(z.first);
15
}
16
}
17
}
18
}
19
for (auto z : sk) {
20
if (z.second == 4 && find(res.begin(), res.end(), z.first) == res.end()) {
21
int p = z.second;
22
for (int aqq = 0; aqq < p; aqq++) {
23
res.push_back(z.first);
24
}
25
}
26

27
if (z.second == 3 && find(res.begin(), res.end(), z.first) == res.end()) {
28
int p = z.second;
29
for (int aq = 0; aq < p; aq++) {
30
res.push_back(z.first);
31
}
32
}
33

34
if (z.second == 2 && find(res.begin(), res.end(), z.first) == res.end()) {
35
int p = z.second;
36
for (int a = 0; a < p; a++) {
37
res.push_back(z.first);
38
}
39
}
40

41
if (z.second == 1 && find(res.begin(), res.end(), z.first) == res.end()) {
42
res.push_back(z.first);
43
}
44
}
45

46
return res;
47
}
48
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0