首页 > 编程语言 > 详细

349. 两个数组的交集

时间:2020-04-22 19:36:12      阅读:62      评论:0      收藏:0      [点我收藏+]
 1 class Solution 
 2 {
 3 public:
 4     vector<int> intersection(vector<int>& nums1, vector<int>& nums2) 
 5     {
 6         vector<int> res;
 7         unordered_map<int,int> hash1,hash2;
 8         for(auto a : nums1) hash1[a] ++;
 9         for(auto a : nums2) hash2[a] ++;
10         for(auto a : hash1)
11         {
12             if(hash2.count(a.first)) res.push_back(a.first);
13         }
14         return res;
15     }
16 };

 

349. 两个数组的交集

原文:https://www.cnblogs.com/yuhong1103/p/12755353.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!