国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

349. Intersection of Two Arrays

2019-11-11 02:15:23
字體:
來源:轉載
供稿:網友

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.

class Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { sort(nums1.begin(), nums1.end()); sort(nums2.begin(), nums2.end()); set<int> s; for(int i = 0, j = 0; 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; } } return vector<int>(s.begin(), s.end()); }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镶黄旗| 南岸区| 循化| 泸水县| 宁海县| 沁源县| 龙州县| 徐水县| 彰武县| 临澧县| 涿鹿县| 崇文区| 湖口县| 通化市| 永济市| 屏边| 固始县| 勃利县| 天气| 招远市| 新源县| 惠来县| 万荣县| 金门县| 岑溪市| 师宗县| 积石山| 麦盖提县| 舒兰市| 慈溪市| 吴堡县| 嘉义县| 平顺县| 雅安市| 庆云县| 黔东| 铜陵市| 衡东县| 化州市| 恩平市| 洞头县|