class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
if (nums1.size() == 0 || nums2.size() == 0)
return vector<int>();
set<int> s;
set<int> ans;
for (auto a : nums1)
s.insert(a);
for (auto b : nums2)
{
if (s.find(b) != s.end())
{
ans.insert(b);
}
}
return vector<int>(ans.begin(), ans.end());
}
};
LeetCode 刷题 349
最新推荐文章于 2024-11-05 21:58:11 发布