349. Intersection of Two Arrays
来源:互联网 发布:lol安妮舞会公主淘宝 编辑:程序博客网 时间:2024/06/01 11:57
排序比对,简单
class Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { sort(nums1.begin(),nums1.end()); sort(nums2.begin(),nums2.end()); set<int> result; int index1=0; int index2=0; while(index1<nums1.size()&&index2<nums2.size()) { if(nums1[index1]==nums2[index2]) { result.insert(nums1[index1]); //cout<<nums1[index1]<<endl; index1++; index2++; //count++; } else if(nums1[index1]<nums2[index2]) index1++; else index2++; } vector<int> resultVec; for(set<int>::iterator it=result.begin();it!=result.end();it++) resultVec.push_back(*it); return resultVec; }};
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
- gulp-concat+uglify+cdnizer实现页面加载优化
- android 创建目录/文件/读写文件
- SparkSQL操作RDD转DataFrame
- hihcoder 1117 战争年代
- 高通平台常见的一些错误(持续更新)
- 349. Intersection of Two Arrays
- omnet++ :Cannot run program Error launch simulation for "项目名"
- Git 基本用法上
- Android自定义view
- LeetCode:Find the Difference
- 让一台电脑只能上一个QQ的方法
- 计算机网络:数据链路层03
- JS的取经之路(四)
- Android studio导入Github的项目