Created
May 28, 2024 18:04
-
-
Save shitu13/72e0d5c635b6926629f3d16455c28a77 to your computer and use it in GitHub Desktop.
Intersection of Two Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { | |
unordered_set<int> uset(nums1.begin(), nums1.end()); | |
vector<int> res; | |
for (int& num : nums2) { | |
if (uset.find(num) != uset.end()) { | |
res.push_back(num); | |
uset.erase(num); | |
} | |
} | |
return res; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment