leetcode-Intersection of Two Arrays-349
来源:互联网 发布:程序员必读书籍 编辑:程序博客网 时间:2024/06/01 10:38
这题的意思其实是求集合的交集,就用set,之后函数返回再用vector的构造函数把set转化成vector。http://www.cnblogs.com/grandyang/p/5507129.html
class Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { set<int> s(nums1.begin(), nums1.end()); set<int> ans; for(int i=0;i<nums2.size();i++){ if(s.count(nums2[i])){ ans.insert(nums2[i]); } } return vector<int>(ans.begin(), ans.end()); }};
0 0
- Leetcode-349 Intersection of Two Arrays
- leetcode 349 Intersection of Two Arrays C++
- LeetCode 349 Intersection of Two Arrays
- LeetCode-349&350.Intersection of Two Arrays
- LeetCode-349 Intersection of Two Arrays
- leetcode-Intersection of Two Arrays-349
- LeetCode 349 Intersection of Two Arrays
- LeetCode#349 Intersection of Two Arrays
- LeetCode(349)Intersection of Two Arrays
- [LeetCode]349 Intersection of Two Arrays
- [LeetCode-349] Intersection of Two Arrays(java)
- Leetcode 349 Intersection of Two Arrays
- LeetCode No.349 Intersection of Two Arrays
- leetcode-349-Intersection of Two Arrays
- [Leetcode 349]Intersection of Two Arrays
- leetcode 349 Intersection of Two Arrays
- Leetcode #349 Intersection of Two Arrays
- LeetCode 349 Intersection of Two Arrays
- PHP 表单提交给自己
- React Native - window 环境安装与配置
- strcmp()和strncmp()函数的实现
- 3.2 虚拟内存管理
- 数据库连接池浅析
- leetcode-Intersection of Two Arrays-349
- oracle11g 拆分字符串的详细技巧
- 如何删除计算机中的服务
- Python 使用ctypes调用C/C++
- PAT乙级.1016. 部分A+B (15)
- Java面试参考指南——同步
- merge into 插入或更新数据
- #Android#集合与异常处理
- 剑指offer——对称的二叉树判断