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

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

349. Intersection of Two Arrays

2019-11-11 00:03:32
字體:
來源:轉載
供稿:網友

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()); }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北碚区| 荣昌县| 忻州市| 通化市| 阳城县| 南宫市| 漠河县| 沛县| 色达县| 金平| 自治县| 彭阳县| 灌阳县| 驻马店市| 林州市| 玉树县| 黄冈市| 应城市| 吴堡县| 东阿县| 松潘县| 福贡县| 汉中市| 独山县| 含山县| 固阳县| 道真| 武平县| 洛南县| 屯留县| 巴南区| 双柏县| 阿勒泰市| 灵璧县| 凭祥市| 日照市| 金阳县| 寿宁县| 略阳县| 普洱| 新巴尔虎左旗|