leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1122.cpp (516B)
0 class Solution {
1 public:
2 vector<int> relativeSortArray(vector<int> &arr1, const vector<int> &arr2) const {
3 const int n = size(arr2);
4 unordered_map<int, int> um;
6 for (int i = 0; i < n; i++)
7 um[arr2[i]] = i;
8 sort(begin(arr1), end(arr1), [&n, &um](int a, int b) {
9 const auto [it1, _1] = um.emplace(a, n + a);
10 const auto [it2, _2] = um.emplace(b, n + b);
12 return it1->second < it2->second;
13 });
15 return arr1;
16 }
17 };