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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

350. Intersection of Two Arrays II

2019-11-11 00:02:09
字體:
供稿:網(wǎng)友

Given two arrays, write a function to compute their intersection.

Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].

Note: Each element in the result should appear as many times as it shows in both arrays. The result can be in any order.

class Solution {public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { sort(nums1.begin(), nums1.end()); sort(nums2.begin(), nums2.end()); vector<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.push_back(nums1[i]); ++i; ++j; } } return s; }};
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 尉氏县| 南昌市| 富源县| 泗水县| 大同县| 班玛县| 泸水县| 海安县| 柯坪县| 仙居县| 深泽县| 商丘市| 报价| 新丰县| 于都县| 临澧县| 长丰县| 北辰区| 普兰县| 衢州市| 高雄市| 方山县| 聂荣县| 洛浦县| 安化县| 温泉县| 宁阳县| 建瓯市| 黔西县| 旬邑县| 合阳县| 财经| 黑河市| 柘荣县| 工布江达县| 富阳市| 天峻县| 金溪县| 黄大仙区| 正镶白旗| 海伦市|