Intersection of Two Arrays 两数组的交
来源:互联网 发布:人工智能和大数据 编辑:程序博客网 时间:2024/05/17 03:39
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.
给出两个数组,写一个函数得出他们的交。
例如:
nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回[2]
备注:
返回值中的每个元素都不一样。
结果可以是任意顺序。
class Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { int len1 = nums1.size(); int len2 = nums2.size(); vector<int> res, nums3; for (int i = 0; i < len1; i++) {//取相同元素插入nums3数组 for (int k = 0; k < len2; k++) { if (nums1[i] == nums2[k]) { nums3.push_back(nums1[i]); break; } } } int len3 = nums3.size(); for (int j = 0; j < len3; j++) {//去除nums3中的不同元素取出插入res数组 int isexit = 0; int len4 = res.size(); for (int m = 0; m < len4; m++) { if (nums3[j] == res[m]) { isexit = 1; break; } } if (isexit == 0) { res.push_back(nums3[j]); } } return res; }};
0 0
- Intersection of Two Arrays 两数组的交
- Intersection of Two Arrays II 两数组的交
- 547.Intersection of Two Arrays-两数组的交(容易题)
- 548.Intersection of Two Arrays II-两数组的交 II(容易题)
- Intersection of Two Arrays(两数组的交叉元素)
- [LeetCode]349. Intersection of Two Arrays(两数组的交集)
- Intersection of Two Arrays II(两数组的交叉元素II)
- 【leetcode75】Intersection of Two Arrays(数组的交集)
- 349. Intersection of Two Arrays | 找两个数组的交集
- [LeetCode] Intersection of Two Arrays 两个数组的交集
- Leetcode :Intersection of Two Arrays 两个数组的交集
- leetcode 349. Intersection of Two Arrays 数组的交集
- Intersection of Two Arrays
- Intersection of Two Arrays
- Intersection of Two Arrays
- Intersection of Two Arrays
- Intersection of Two Arrays
- Intersection of Two Arrays
- Redis中modules扩展模块的开发使用详解
- [BZOJ]1088: [SCOI2005]扫雷Mine[乱搞DP]
- javascript原型模式
- mysql模拟窗口函数功能
- Java WebService
- Intersection of Two Arrays 两数组的交
- 无需ROOT权限调试A ndroid UI布局。
- cordova之自定义插件
- 解答:ipa进行重签名的时候,报"error provisioning failed"的问题
- gradle
- GROUP BY分组查询与SQL执行顺序
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 第一篇
- apache报中文“以一种访问权限不允许的方式做了一个访问套接字的尝试”