找两个数组的交叉部分,可以用map进行标记

首先对第一个数组进行记录,第二个数组在第一个数组记录基础上进行判断,如果在第一个数组出现过,就记录

 class Solution {
public:
vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
map<int,int>p_map;
vector<int>p_vec;
for(int i=;i<nums1.size();i++)
p_map[nums1[i]]++;
for(int i=;i<nums2.size();i++) {
p_map[nums2[i]]--;
if(p_map[nums2[i]]>=)
p_vec.push_back(nums2[i]);
}
return p_vec;
}
};

leetcode 350的更多相关文章

  1. 前端与算法 leetcode 350. 两个数组的交集 II

    目录 # 前端与算法 leetcode 350. 两个数组的交集 II 题目描述 概要 提示 解析 解法一:哈希表 解法二:双指针 解法三:暴力法 算法 # 前端与算法 leetcode 350. 两 ...

  2. [LeetCode] 350. Intersection of Two Arrays II 两个数组相交之二

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

  3. 26. leetcode 350. Intersection of Two Arrays II

    350. Intersection of Two Arrays II Given two arrays, write a function to compute their intersection. ...

  4. LeetCode 350. Intersection of Two Arrays II (两个数组的相交之二)

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  5. [LeetCode] 350. Intersection of Two Arrays II 两个数组相交II

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

  6. leetcode 350 easy

    350. Intersection of Two Arrays II class Solution { public: vector<int> intersect(vector<in ...

  7. Java实现 LeetCode 350 两个数组的交集 II(二)

    350. 两个数组的交集 II 给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入 ...

  8. LeetCode 350. Intersection of Two Arrays II

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  9. Python [Leetcode 350]Intersection of Two Arrays II

    题目描述: Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, ...

  10. Leetcode 350.两个数组的交集|| By Python

    给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入: nums1 = [4,9,5 ...

随机推荐

  1. vijos 1190 繁忙的都市

    描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条道路 ...

  2. MFC技术积累——基于MFC对话框类的那些事儿3

    3.3.2 创建图形画刷来实现位图加载 1.首先在Resource View中导入一幅位图,位图大小96×96像素: 2.其次在主对话框中添加一个静态文本资源,ID号是IDC_BITMAPAREA,添 ...

  3. 图片,二进制,oracle数据库

    图片在oracle数据库中一般以二进制存在,存储类型是blob,然而clob类型一般存储的是大于4000的字符,不能用来存储图像这样的二进制内容,下面展示一下实现图像,二进制,oracle 数据库的应 ...

  4. 如何实现第二窗口不显示在windows下面的任务栏中

    将要隐藏的窗体的的ShowInTaskBar属性设置为false;就好了

  5. eclipse 在写XML时 包类名自动提醒的问题

    需要加一个STS插件 配置很简单 参考了  https://blog.csdn.net/HH775313602/article/details/70176531 在 https://spring.io ...

  6. linux 5.7.20和5.6.38版本 数据库忘记root密码怎么找回?

    1.    5.6.38版本的数据库密码丢失找回方法: 第一步.关数据库 第二步:mysqld_safe --skip-grant-tables --skip-networking & 第三步 ...

  7. 【计算机网络】Session机制

    1. Http请求中Session机制 先简单说一下HTTP请求中的Session机制:Session数据保存在服务器端,SessionID保存在客户端的Cookies中(关闭浏览器时过期).当客户端 ...

  8. 前端开发中提到的“脚手架”到底指什么,CLI?gulp 和 gulp-cli有什么区别

    一般来说,脚手架是帮你减少「为减少重复性工作而做的重复性工作」的工具. gulp和gulp-cli的区别可以看这个task - what does gulp-"cli" stand ...

  9. day20-python之装饰器

    1.装饰器 #!/usr/bin/env python # -*- coding:utf-8 -*- import time def cal(l): start_time=time.time() re ...

  10. C/C++编程之内存管理

    内存分配方式 内存分配方式一共有三种: (1)从静态存储区域分配: 内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在,例如,全局变量,静态变量. (2)在栈上创建: 在执行函数时, ...