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

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

350. Intersection of Two Arrays II

2019-11-11 02:14:57
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 安丘市| 宁国市| 定结县| 桑日县| 杂多县| 独山县| 开封县| 鱼台县| 阳城县| 米易县| 进贤县| 道孚县| 太白县| 武冈市| 普宁市| 青川县| 峡江县| 辽宁省| 敖汉旗| 康平县| 易门县| 天气| 湘阴县| 威信县| 赤城县| 上思县| 运城市| 镇安县| 建昌县| 红安县| 威远县| 乡城县| 铅山县| 增城市| 陇西县| 汕头市| 泸定县| 永寿县| 嘉义市| 和林格尔县| 桐乡市|