350. Intersection of Two Arrays II
来源:互联网 发布:mac vim 修改只读文件 编辑:程序博客网 时间:2024/06/07 10:05
题目:
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
, return [2, 2]
.
Note:
- Each element in the result should appear as many times as it shows in both arrays.
- The result can be in any order.
本题与前一篇博客:Intersection of Two Arrays有些许的不同,前一篇博客,是找到交叉线,不保留重复值,本篇博客是找到交叉项,保留重复值。本题采用find函数
代码:
class Solution {public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { vector<int> res; for(int j = 0;j<nums1.size();j++) { vector<int>::iterator itr = find(nums2.begin(),nums2.end(),nums1[j]); if(itr!=nums2.end()) { res.push_back(*itr); nums2.erase(itr); } } return res; }};
阅读全文
1 0
- 350. Intersection of Two Arrays II
- LeetCode 350. Intersection of Two Arrays II
- leetcode.350. Intersection of Two Arrays II
- 350. Intersection of Two Arrays II【E】
- 350. Intersection of Two Arrays II
- [leetcode] 350. Intersection of Two Arrays II
- Leetcode 350. Intersection of Two Arrays II
- leetcode 350. Intersection of Two Arrays II
- 350. Intersection of Two Arrays II
- 350. Intersection of Two Arrays II
- Leetcode 350. Intersection of Two Arrays II
- [leetcode] 350. Intersection of Two Arrays II
- leetcode 350. Intersection of Two Arrays II
- 350. Intersection of Two Arrays II
- 350. Intersection of Two Arrays II
- 【leetcode】350. Intersection of Two Arrays II
- 350. Intersection of Two Arrays II
- 350. Intersection of Two Arrays II
- 我的配置(vc可以禁止控制台输出)
- React Native安卓应用调试填坑记录
- OpenGL鼠标拾取的实现:终于搞定(包括细节问题)
- "streambuf" ambiguous symbol的问题如何解决
- HDU1083---Courses (二分图匹配)
- 350. Intersection of Two Arrays II
- 后台过滤器处理跨域请求问题
- VC解决error C2065: 'timeGetTime' : undeclared identi
- 隐藏easyui-datagrid表头的checkbox
- 8.7 K
- PAT 乙级 1026.程序运行时间(15)
- 完全卸载Oracle
- 数值设计的原则
- OpenGL 有时候纹理映射的部分问题