国产探花免费观看_亚洲丰满少妇自慰呻吟_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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 稻城县| 民勤县| 清丰县| 河北区| 临清市| 德庆县| 上思县| 本溪| 富蕴县| 耿马| 通化县| 河北区| 汉沽区| 秀山| 子长县| 静海县| 青铜峡市| 观塘区| 得荣县| 呼伦贝尔市| 清丰县| 汉阴县| 石首市| 永泰县| 丽江市| 龙胜| 万载县| 东宁县| 和龙市| 手游| 武安市| 罗甸县| 资源县| 葫芦岛市| 正蓝旗| 嵩明县| 甘谷县| 深泽县| 常熟市| 绍兴市| 雅江县|