349. Intersection of Two Arrays 难度:easy
来源:互联网 发布:鹏业软件视频教程 编辑:程序博客网 时间:2024/06/05 17:36
题目:
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
, return [2]
.
程序:
class Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { set<int> s; vector<int> res; sort(nums1.begin(),nums1.end()); sort(nums2.begin(),nums2.end()); int i = 0; int j = 0; while(i < nums1.size()&&j < nums2.size()) { if(nums1[i] < nums2[j]) i++; else if(nums1[i] > nums2[j]) j++; else { s.insert(nums1[i]); i++; j++; } } for(set<int>::iterator p = s.begin();p != s.end();p++) res.push_back(*p); return res; }};
0 0
- 349. Intersection of Two Arrays 难度:easy
- 350. Intersection of Two Arrays II 难度:easy
- 349. Intersection of Two Arrays [easy] (Python)
- Leetcode 349. Intersection of Two Arrays (Easy) (cpp)
- 349.leetcode Intersection of Two Arrays(easy)[数组 交集 set]
- LeetCode解题报告 349. Intersection of Two Arrays [easy]
- Easy 349题 Intersection of Two Arrays
- leetcode 349[easy]---Intersection of Two Arrays
- LeetCode-Easy部分中标签为 Binary Search 349. Intersection of Two Arrays 350. Intersection of Two Arrays II
- 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
- Error connecting to server :致命错误 SSL关闭的pg_hba.conf记录
- EF操作存储过程调用
- OK6410 uboot启动流程详解(一)
- jquery自适应浏览器高度,兼容性好
- StringBuffe与StringBuilder的使用
- 349. Intersection of Two Arrays 难度:easy
- Android 之MediaScanner流程解析
- B-tree 索引提高 MySQL 查询效率的原理
- 彻底理解js中this的指向
- Qt 实现在隐藏标题栏情况下,窗口的缩放(未成功)
- 不需要在清单文件中注册的Acrivity的启动方式--Hook技术
- Linux下用管道执行base64命令加密解密字符串
- Bootstrap3 表单-辅助文本
- [JAVA] 数字格式化显示方法