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

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

350. Intersection of Two Arrays II

2019-11-11 01:00:26
字體:
來源:轉載
供稿:網友

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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿尔山市| 晋宁县| 新民市| 盐津县| 合作市| 杭锦旗| 左贡县| 临颍县| 舒城县| 茶陵县| 晋州市| 新昌县| 泸水县| 绥芬河市| 封开县| 梅河口市| 客服| 安康市| 枣庄市| 南京市| 兴文县| 大庆市| 岑溪市| 山西省| 襄樊市| 彭州市| 扶风县| 扎兰屯市| 贵港市| 瑞丽市| 揭东县| 上饶县| 阳泉市| 丰台区| 淳化县| 涪陵区| 裕民县| 秀山| 秀山| 汶川县| 韶山市|