349. Intersection of Two Arrays
来源:互联网 发布:java编程用记事本 编辑:程序博客网 时间:2024/05/18 18:21
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
, return [2]
.
Note:
- Each element in the result must be unique.
- The result can be in any order.
Subscribe to see which companies asked this question.
class Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { map<int,int> m; int n1 =nums1.size(); int n2 = nums2.size(); for(int i =0;i<n1;i++) m[nums1[i]]++; vector<int> res; for(int i=0;i<n2;i++){ if(m[nums2[i]]!=0){ res.push_back(nums2[i]); m[nums2[i]]=0; } } return res; }};
0 0
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays[][
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- bzoj 1272: [BeiJingWc2008]Gate Of Babylon (容斥原理+Lucas定理)
- LeetCode : Reverse Vowels of a String
- 编码问题解决方案
- Accelerated C++<4-1>
- 交换类排序:冒泡排序(优化)和快排
- 349. Intersection of Two Arrays
- 一个简单的题让我了解算法并且喜欢上了她
- 超实用!常用开源许可证有啥区别。
- 机器学习:空间变换进行非线性分类
- 树和二叉树
- LinearLayout 和 RelativeLayout onMeasure理解(一)
- 新手配置Hadoop教程整理
- 进制间转换的小窍门
- 无穷小的比较