https://leetcode.com/problems/intersection-of-two-arrays-ii/

class Solution {
public:
vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
multiset<int> ms(nums1.begin(), nums1.end());
vector<int> result;
for (vector<int>::iterator itr=nums2.begin();
itr != nums2.end();
++itr) {
multiset<int>::iterator mitr = ms.find(*itr);
if (mitr != ms.end()) {
result.push_back(*itr);
ms.erase(mitr);
}
}
return result;
}
};

intersection-of-two-arrays-ii的更多相关文章

  1. [LintCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection.Notice Each element in the result s ...

  2. 26. leetcode 350. Intersection of Two Arrays II

    350. Intersection of Two Arrays II Given two arrays, write a function to compute their intersection. ...

  3. [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II

    这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...

  4. LeetCode Javascript实现 169. Majority Element 217. Contains Duplicate(两个对象比较是否相等时,如果都指向同一个对象,a==b才是true)350. Intersection of Two Arrays II

    169. Majority Element /** * @param {number[]} nums * @return {number} */ var majorityElement = funct ...

  5. 【leetcode】350. Intersection of Two Arrays II

    problem 350. Intersection of Two Arrays II 不是特别明白这道题的意思,例子不够说明问题: 是按顺序把相同的元素保存下来,还是排序,但是第二个例子没有重复... ...

  6. LeetCode_350. Intersection of Two Arrays II

    350. Intersection of Two Arrays II Easy Given two arrays, write a function to compute their intersec ...

  7. [LeetCode] Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  8. LeetCode Intersection of Two Arrays II

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...

  9. 【一天一道LeetCode】#350. Intersection of Two Arrays II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  10. [LeetCode] 350. Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

随机推荐

  1. 局域网 其它主机ping不通win7, 解决

    默认情况下,Windows 7出于安全考虑不允许外部主机对其进行Ping测试. 允许ICMP回显 设置如下: 1. 打开win7防火墙设置界面 2. 左边的菜单中选择 [高级设置] 3. 在弹出的 [ ...

  2. Spark函数

    这张图不错!

  3. mini.open打开窗口时传递参数

    mini.open({ url: "xxx.html", showMaxButton: false, allowResize: false, title: '标题', width: ...

  4. android 代码整体回退

    repo forall -c 'HAHA=`git log --before="3 days" -1 --pretty=format:"%H"`;git res ...

  5. Paths on a Grid(简单组合数学)

    Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Desc ...

  6. Java根据条件删除Map中元素

    今天在写程序过程中,需要根据判断条件删除一个Map中的相应数据,我自然而然想到可以通过调用Map中的remove(Object key)函数进行删除:代码如下: public Map<Doubl ...

  7. NSIS学习记录の----NSIS多语言安装以及详解

    NSIS多语言安装,很多教程提供了详细的代码,但是代码中某些语句的含义我还是不很明白,作为一个吃螃蟹的人,我做一个解释,避免很多小伙伴和我哟U一样的误区,以下结论都是自己根据实践得来,若发现理解错误, ...

  8. 没有必要去指定SqlSessionFactory或SqlSessionTemplate

    <!-- 自动注册mybatis mapper bean --><!-- 注意,没有必要去指定SqlSessionFactory或SqlSessionTemplate,     因为 ...

  9. Spring中MultipartHttpServletRequest实现文件上传

    Spring中MultipartHttpServletRequest实现文件上传 转贴自:http://my.oschina.net/nyniuch/blog/185266 实现图片上传  用户必须能 ...

  10. 你不知道的This和Class

    Oh no....我的This又丢失了??? 为什么我用Class'实例化'出来的对象会相互影响??? ####这些问题都是因为JS的运行机制造成的.在JS中所有的一切都是对象,而this是对象的一个 ...