leetcode-350-Intersection of Two Arrays II
2017-01-14 13:08
411 查看
问题
题目:[leetcode-350]思路
感觉这道题比之前那道更简单,都不用考虑重复的情形。当然用集合还是最快,我试了下两个指针也可以。
代码
class Solution { public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { int i = 0; int j = 0; int sz1 = nums1.size(); int sz2 = nums2.size(); std::sort(nums1.begin(), nums1.end()); std::sort(nums2.begin(), nums2.end()); std::vector<int> ret; while( i < sz1 && j < sz2 ){ if( nums1[i] < nums2[j] ) ++i; else if( nums1[i] > nums2[j] ) ++j; else{ ret.push_back( nums1[i] ); ++i; ++j; } } return ret; } };
相关文章推荐
- [leetcode][350] Intersection of Two Arrays II
- leetcode 350 Intersection of Two Arrays II C++
- leetcode note--leetcode 350 Intersection of Two Arrays II
- Leetcode_350_Intersection of Two Arrays II
- LeetCode 350 Intersection of Two Arrays II
- leetcode_350 Intersection of Two Arrays II
- leetcode350——Intersection of Two Arrays II
- LeetCode-350 Intersection of Two Arrays II
- [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II
- leetcode 350 Intersection of two arrays II
- LeetCode(350)Intersection of Two Arrays II
- leetcode-Intersection of Two Arrays II-350
- leetcode_c++:哈希:Intersection of Two Arrays II(350)
- leetcode350~Intersection of Two Arrays II
- Leetcode 350 Intersection of Two Arrays II
- LeetCode 350 Intersection of Two Arrays II
- LeetCode 350:Intersection of Two Arrays II
- <LeetCode OJ> 349 / 350 Intersection of Two Arrays(I / II)
- Leetcode 350 Intersection of Two Arrays II
- Leetcode-350-Intersection of Two Arrays II