国产探花免费观看_亚洲丰满少妇自慰呻吟_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()); }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 张家港市| 长海县| 常山县| 大同县| 高唐县| 乾安县| 张家港市| 芦溪县| 沽源县| 宜宾市| 莎车县| 抚顺市| 崇礼县| 当雄县| 庆城县| 紫阳县| 阿荣旗| 福贡县| 莲花县| 西城区| 稻城县| 嘉定区| 鄂托克旗| 丰城市| 临沂市| 浪卡子县| 新沂市| 荆州市| 青龙| 寿阳县| 霸州市| 凉城县| 泸定县| 黄梅县| 大田县| 镇康县| 龙江县| 洛南县| 大姚县| 余江县| 尤溪县|