Intersection of Two Arrays II
来源:互联网 发布:冷漠的文字软件 编辑:程序博客网 时间:2024/05/18 10:36
C++
class Solution {public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { if (nums1.empty()) return nums1; if (nums2.empty()) return nums2; map<int, int> store; for (auto v : nums1) { store[v]++; } vector<int> result; for (auto v : nums2) { if (store[v] > 0) { result.push_back(v); store[v]--; } } return result; }};
Python
class Solution(object): def intersect(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ store = {} for x in nums1: if store.get(x, 'N/A') == 'N/A': store[x] = 1 else: store[x] = store[x] + 1 result = [] for v in nums2: if store.get(v, 'N/A') != 'N/A' and store.get(v, 'N/A') > 0: result.append(v) store[v] = store[v]-1 return result
0 0
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays II
- Intersection of Two Arrays&Intersection of Two Arrays II
- [LeetCode] Intersection of Two Arrays II
- 350. Intersection of Two Arrays II
- LeetCode Intersection of Two Arrays II
- android知识库
- Elasticsearch集成ik分词器
- android 打开系统相册得到路径 上传图片到php服务器
- 关于mysql安装的个人整理
- div ul li自动适应高度float:left
- Intersection of Two Arrays II
- XCode 7.3.1(dmg) 官方直接下载地址(离线下载)
- Android push 原理 分析
- iOS 模拟器安装.app
- 剑指offer-面试题8:旋转数组中的最小数字
- Hbuilder开发移动新闻客户端(二)
- Activiti工作流引擎使用
- 配置eclipse的java代码注解的模板
- LeetCode-135.Candy