349 Intersection of Two Arrays 两个数组的交集
给定两个数组,写一个函数来计算它们的交集。
例子:
给定 num1= [1, 2, 2, 1], nums2 = [2, 2], 返回 [2].
提示:
每个在结果中的元素必定是唯一的。
我们可以不考虑输出结果的顺序。
详见:https://leetcode.com/problems/intersection-of-two-arrays/description/
C++:
class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
set<int> s(nums1.begin(),nums1.end()),res;
for(auto num:nums2)
{
if(s.count(num))
{
res.insert(num);
}
}
return vector<int>(res.begin(),res.end());
}
};
参考:https://www.cnblogs.com/grandyang/p/5507129.html
349 Intersection of Two Arrays 两个数组的交集的更多相关文章
- [LeetCode] 349. Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- [LeetCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LintCode] Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection.Notice Each element in the result m ...
- [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II
这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...
- LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List
283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...
- Java实现 LeetCode 349 两个数组的交集
349. 两个数组的交集 给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2] 示例 2: 输入: num ...
- 【easy】349. Intersection of Two Arrays
找两个数组的交集(不要多想,考虑啥序列之类的,就是简单的两堆数求交集啊!!!最后去个重就好了) //LeetCode里用到很多现成函数的时候,苦手だな- //这个题的思路是,先sort,把两个vect ...
- 【LeetCode题解】349_两个数组的交集
目录 [LeetCode题解]349_两个数组的交集 描述 方法一:两个哈希表 Java 实现 类似的 Java 实现 Python 实现 类似的 Python 实现 方法二:双指针 Java 实现 ...
- Leecode刷题之旅-C语言/python-349两个数组的交集
/* * @lc app=leetcode.cn id=349 lang=c * * [349] 两个数组的交集 * * https://leetcode-cn.com/problems/inters ...
随机推荐
- radial profiles of mean streamwise velocity at X/D=3
matlab code: load aver_ux_array.dat; load z_array.dat; r=z_array(:,); r=r.' r_j=0.00125; r_nor=r/d; ...
- MySql 执行计划解读
说明 解读执行计划l对于我们日常工作中慢sql的分析和调优有很大帮助,同时在解读的过程中也能知道如何规避慢sql 建议需要了解join匹配原理的知识:https://www.cnblogs.com/L ...
- 【ZJOI2017 Round2练习】
………………………………………………………………………… DAY1:听说是湖南的题 T1:spaly?毫无想法,写个暴力压压惊 T2:尼克杨问号脸 T3:FFT我不会啊,70points已经尽力了
- Wikioi 3776 生活大爆炸版石头剪子布
题目描述 Description 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8集中出现了一种石头剪刀布的升级版游戏 ...
- Ubuntu18.04卸载lnmp
1.卸载 apache2 sudo apt-get --purge remove apache2* sudo apt-get autoremove apache2 (--purge 是完全删除并且不保 ...
- 【UI自动化方面】
1.自动化执行失败如何排查故障. 答:1).查看log,错误原因.[log不详细的话,可以优化] 2).排查是否真的有bug,若不是bug查看是否是新版本引入了新的变更. 3).调试脚本看自己脚本是不 ...
- Unity3D-碰撞測试
碰撞測试这个再游戏的开发中是非常有必要的.当敌人的攻击的时候,发生碰撞这时候就会造成一定的伤害,因此我们须要依据受到的伤害对用户的生命值进行控制,因此碰撞的測试是 我们在游戏的开发过程中须要的一种比較 ...
- Magento 模块开发之DispatchEvent
在这一章节中.我们来了解 Magento 中的事件分发机制 Mage::dispatchEvent() 在创建自己的模块时, Event 事件的分发将会变成十分实用且有效 以个人的经验. 事件的分发使 ...
- poj 3020 Antenna Placement(二分无向图 匈牙利)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6438 Accepted: 3176 ...
- 全然卸载oracle11g步骤
iLife's 博客http://blog.csdn.net/fei1502816 全然卸载oracle11g步骤: 1. 開始->设置->控制面板->管理工具->服务 停止全 ...