Data Structure I: Day 3
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
@@ -0,0 +1,15 @@
class Solution {
public:
vector<int> intersect(vector<int> &nums1, vector<int> &nums2) {
unordered_multiset<int> s(nums1.begin(), nums1.end());
vector<int> res;
for (int n : nums2) {
const auto it = s.find(n);
if (it == s.end()) continue;
s.erase(it);
res.push_back(n);
}
return res;
}
};
@@ -143,6 +143,7 @@
for solving problems.
| 0344 | Easy | [Reverse String](Problems/0344.cpp) |
| 0345 | Easy | [Reverse Vowels of a String](Problems/0345.cpp) |
| 0347 | Medium | [Top K Frequent Elements](Problems/0347.cpp) |
| 0350 | Easy | [Intersection of Two Arrays II](Problems/0350.cpp) |
| 0374 | Easy | [Guess Number Higher or Lower](Problems/0374.cpp) |
| 0383 | Easy | [Ransom Note](Problems/0383.cpp) |
| 0387 | Easy | [First Unique Character in a String](Problems/0387.cpp) |