commit f34df98334698d4b4473bdc3de5e3abd31288b74
parent 79f04f1e7c8a523b9946aa34eb26030b99c3e4d5
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 24 Jan 2023 13:54:50 +0100
Data Structure I: Day 3
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/Problems/0350.cpp b/Problems/0350.cpp
@@ -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;
+ }
+};
diff --git a/README.md b/README.md
@@ -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) |