首页 > 编程语言 > 详细

350. 两个数组的交集 II

时间:2020-04-22 20:33:38      阅读:57      评论:0      收藏:0      [点我收藏+]
 1 class Solution 
 2 {
 3 public:
 4     vector<int> intersect(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)) 
13             {
14                 int count = min(a.second,hash2[a.first]);
15                 while(count --) res.push_back(a.first);
16             }
17         }
18         return res;
19     }
20 };

 

350. 两个数组的交集 II

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

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