2191. Sort the Jumbled Numbers
class Solution {
public:
vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums)
{
vector<pair<int, int>> m;
for (int i = 0; i < nums.size(); ++i)
{
string number = to_string(nums[i]);
string formed = "";
for (int j = 0; j < number.size(); ++j)
{
formed = formed + (to_string(mapping[number[j] - '0']));
}
int mappedValue = stoi(formed);
m.push_back({mappedValue, i});
}
sort(m.begin(), m.end());
vector<int> res;
for (auto pair : m)
{
res.push_back(nums[pair.second]);
}
return res;
}
};
- T:
- S: