国产探花免费观看_亚洲丰满少妇自慰呻吟_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()); }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桐梓县| 安平县| 龙口市| 永泰县| 股票| 大竹县| 昌图县| 岳阳市| 历史| 绥化市| 江华| 仁布县| 祁连县| 梁河县| 德州市| 宜阳县| 平邑县| 顺昌县| 酒泉市| 渑池县| 油尖旺区| 平乐县| 社会| 和硕县| 盱眙县| 庆安县| 阳城县| 五台县| 稷山县| 安新县| 栾川县| 通道| 盐津县| 泌阳县| 甘南县| 灵川县| 沾益县| 容城县| 平邑县| 于都县| 濮阳市|