Created
July 18, 2022 12:37
-
-
Save icameling/78b641c52ad12543818305b8920bbe8a to your computer and use it in GitHub Desktop.
#哈希表 #两个数组的交集
This file contains hidden or 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> same_set; | |
unordered_set<int> num1_set(nums1.begin(), nums1.end()); | |
for (auto num : nums2) { | |
if (num1_set.find(num) != num1_set.end()) | |
same_set.insert(num); | |
} | |
return vector<int>(same_set.begin(), same_set.end()); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment