leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | ac5b68626e56edd5f0c2bcc4c40cab49d15bb983 |
parent | 3a1d42abe881264e1da1fb2c4ebb2363e945d6be |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Tue, 11 Jun 2024 09:34:28 +0200 |
Daily Problem
Diffstat:A | Problems/1122.cpp | | | ++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Problems/1122.cpp b/Problems/1122.cpp
@@ -0,0 +1,18 @@
class Solution {
public:
vector<int> relativeSortArray(vector<int> &arr1, const vector<int> &arr2) const {
const int n = size(arr2);
unordered_map<int, int> um;
for (int i = 0; i < n; i++)
um[arr2[i]] = i;
sort(begin(arr1), end(arr1), [&n, &um](int a, int b) {
const auto [it1, _1] = um.emplace(a, n + a);
const auto [it2, _2] = um.emplace(b, n + b);
return it1->second < it2->second;
});
return arr1;
}
};
diff --git a/README.md b/README.md
@@ -667,6 +667,7 @@ for solving problems.
| 1109 | Medium | [Corporate Flight Bookings](Problems/1109.cpp) |
| 1110 | Medium | [Delete Nodes And Return Forest](Problems/1110.cpp) |
| 1111 | Medium | [Maximum Nesting Depth of Two Valid Parentheses Strings](Problems/1111.cpp) |
| 1122 | Easy | [Relative Sort Array](Problems/1122.cpp) |
| 1123 | Medium | [Lowest Common Ancestor of Deepest Leaves](Problems/1123.cpp) |
| 1125 | Hard | [Smallest Sufficient Team](Problems/1125.cpp) |
| 1129 | Medium | [Shortest Path with Alternating Colors](Problems/1129.cpp) |