-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2191.cpp
More file actions
23 lines (22 loc) · 755 Bytes
/
2191.cpp
File metadata and controls
23 lines (22 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
int num2num(int num, vector<int>& mapping) {
string out = to_string(num);
for (int i = 0; i < out.size(); i++) {
out[i] = mapping[out[i] - '0'] + '0';
}
return stoi(out);
}
vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {
vector<pair<int, int>> translatedNums;
for (int i = 0; i < nums.size(); i++) {
translatedNums.push_back(make_pair(num2num(nums[i], mapping), i));
}
sort(translatedNums.begin(), translatedNums.end());
vector<int> out;
for (int i = 0; i < translatedNums.size(); i++) {
out.push_back(nums[translatedNums[i].second]);
}
return out;
}
};