leetcode 349 map
只需要用map来标记1,今儿通过map的值来得到重叠的部分
class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
map<int,int>hash;
vector<int>nums3;
for(int i=;i<nums1.size();i++)
hash[nums1[i]]=;
for(int i=;i<nums2.size();i++)
if(hash[nums2[i]]) {
nums3.push_back(nums2[i]);
hash[nums2[i]]=;
}
return nums3;
}
};
leetcode 349 map的更多相关文章
- LeetCode 349,350 数组的交集
LeetCode 349: package com.lt.datastructure.Set; import java.util.ArrayList; import java.util.LinkedH ...
- [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II
这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...
- LeetCode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- leetcode 389 map iterator 的使用
class Solution { public: char findTheDifference(string s, string t) { map<char,int>Map_Temp; ; ...
- LeetCode 349. Intersection of Two Arrays (两个数组的相交)
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- [LeetCode] 349. Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- LeetCode 677. Map Sum Pairs 键值映射(C++/Java)
题目: Implement a MapSum class with insert, and sum methods. For the method insert, you'll be given a ...
- Java实现 LeetCode 349 两个数组的交集
349. 两个数组的交集 给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2] 示例 2: 输入: num ...
- leetcode 349:两个数组的交集I
Problem: Given two arrays, write a function to compute their intersection. 中文:已知两个数组,写一个函数来计算它们的交集 E ...
随机推荐
- 面试题--JAVA中静态块、静态变量加载顺序
最后给大家一道面试题练练手,要求写出其结果(笔试) public class StaticTest { public static int k = 0; public static StaticTes ...
- COGS 2334. [HZOI 2016]最小函数值
时间限制:1 s 内存限制:128 MB [题目描述] 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Aix2+Bix+Ci(x∈N∗).给定这些Ai.Bi和Ci,请求出所有函数的所 ...
- Freemarker入门小案例(生成静态网页的其中一种方式)
其实生成静态网页的方式有好多种,我昨天看了一下,Freemarker是其中一种,但是Freemarker现在我们都用得比较少了,现在用得ActiveMQ用来发送信息到静态页面,不过想了一下这个小东西, ...
- VC-基础:MFC单文档程序架构解析
MFC单文档程序架构解析 这里我以科院杨老师的单文档程序来分析一下MFC单文档的程序架构,纯属个人见解,不当之处烦请指教! 首先我们了解到的是 图(一) theApp 是唯一一个在程序形成的时候就存在 ...
- C# 使用Epplus导出Excel [2]:导出动态列数据
C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...
- 拖拽大图轮播pc 移动兼容
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- GIMP中的新建Layer与更改Layer大小
这边可以直接New Layer,新建一个Layer,还可以New from Visible,第二种是将当前的状态下图像复制出来. 改变Layer的大小,一般的方法两种: Crop to Selecti ...
- opencast 视频捕获代理 pyCA安装和功能实现
pyCA安装过程: 36 git clone https://github.com/opencast/pyCA.git 37 cd pyCA/ 41 yum install python-pycurl ...
- The North American Invitational Programming Contest 2018 H. Recovery
Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4: \displaystyle \ ...
- 封装微信分享到朋友/朋友圈js
在页面引入: <script src="/static/lib/jquery-2.2.2.min.js"></script><script src=& ...