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. 关于left join、right join和inner join

    总结, 1.select * from A left join B on A.XX=B.XX 左侧显示A的列名,右侧显示B的列名 左侧,显示A表的所有列 右侧, A.XX=B.XX的时候,显示B表的列 ...

  2. SlickGrid example 2: 按想要的风格展示列

    先上效果图. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// ...

  3. extjs 中动态给gridpanel 复选框赋值

    最近在搞extjs时需要动态根据数据给gridpanel的复选框赋值 网上看了很多 ,多不行,最后找到一个好使的方法 如下: RBACformPanel.getSelectionModel().sel ...

  4. hdu1024 Max Sum Plus Plus

    动态规划,给定长度为n(≤1e6)的整数数组和整数m,选取m个连续且两两无交集的子区间,求所有方案中使得区间和最大的最大值. dp[i][j]表示结束位置(最后一个区间最后一个元素的位置)为i且选取区 ...

  5. c#中的委托和事件(转)

    引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...

  6. Poj(1274),二分图匹配

    题目链接:http://poj.org/problem?id=1274 The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Tota ...

  7. ISO C90 forbids mixed declarations and code 警告

    编译的时候经常会遇到   ISO C90 forbids mixed declarations and code 警告百度了一下,知道是如下原因 : 变量定义之前任何一条非变量定义的语句(注意:语句是 ...

  8. 2-Babel

    一.什么是babel babel是一个源代码到源代码的转换器.比较广泛的用法就是可以把你写的符合 ECMAScript 6 标准的代码完美地转换为 ECMAScript 5 标准的代码,并且可以确保良 ...

  9. CUBRID学习笔记17 事务的回滚

    语法:ROLLBACK [ WORK ] 下面的语句会报错 ALTER TABLE code DROP s_name; INSERT INTO code (s_name, f_name) VALUES ...

  10. 随机步法A-Z

    程序是生成一个10X10的字符数组,初始化时全为 ‘.’  的随机步法.程序必须随机的从一个元素 ‘走到’ 另一个元素,每次只向上.向下.向左或向右移动一个元素位置.已访问过的元素按访问顺序用字母A到 ...