国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 太保市| 惠安县| 蓝山县| 青川县| 江油市| 伊金霍洛旗| 乌审旗| 新野县| 乌鲁木齐县| 安远县| 宝丰县| 峨边| 新宾| 金堂县| 孝昌县| 台州市| 凤城市| 炉霍县| 分宜县| 遂溪县| 彰武县| 济宁市| 牙克石市| 霸州市| 孟津县| 佛冈县| 六枝特区| 平定县| 扎赉特旗| 沿河| 奉节县| 临桂县| 青岛市| 郎溪县| 古交市| 阜阳市| 攀枝花市| 永善县| 化州市| 永兴县| 沙田区|