forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelative Sort Array.cpp
50 lines (44 loc) · 1.45 KB
/
Relative Sort Array.cpp
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
46
47
48
49
50
class Solution {
public:
vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {
map<int,int>sk;
vector<int>res;
for(auto i:arr1){
sk[i]++;
}
for(auto j:arr2){
for(auto z:sk){
if(z.first==j){
int x=z.second;
for(int l=0;l<x;l++){
res.push_back(z.first);
}
}
}
}
for(auto z:sk){
if(z.second==4 && find(res.begin(), res.end(),z.first)==res.end()){
int p=z.second;
for(int aqq=0;aqq<p;aqq++){
res.push_back(z.first);
}
}
if(z.second==3 && find(res.begin(), res.end(),z.first)==res.end()){
int p=z.second;
for(int aq=0;aq<p;aq++){
res.push_back(z.first);
}
}
if(z.second==2 && find(res.begin(), res.end(),z.first)==res.end()){
int p=z.second;
for(int a=0;a<p;a++){
res.push_back(z.first);
}
}
if(z.second==1 && find(res.begin(), res.end(),z.first)==res.end()){
res.push_back(z.first);
}
}
return res;
}
};