只需要用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的更多相关文章

  1. LeetCode 349,350 数组的交集

    LeetCode 349: package com.lt.datastructure.Set; import java.util.ArrayList; import java.util.LinkedH ...

  2. [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II

    这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...

  3. LeetCode 349. Intersection of Two Arrays

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

  4. leetcode 389 map iterator 的使用

    class Solution { public: char findTheDifference(string s, string t) { map<char,int>Map_Temp; ; ...

  5. LeetCode 349. Intersection of Two Arrays (两个数组的相交)

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

  6. [LeetCode] 349. Intersection of Two Arrays 两个数组相交

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

  7. 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 ...

  8. Java实现 LeetCode 349 两个数组的交集

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

  9. leetcode 349:两个数组的交集I

    Problem: Given two arrays, write a function to compute their intersection. 中文:已知两个数组,写一个函数来计算它们的交集 E ...

随机推荐

  1. ActiveMQ消息丢失怎么解决?

    在消息发送过程中消息丢失的话该怎么解决(包括网络原因): 解决思路: 可以把消息唯一ID,存到表里面,当消息接受端可以获取到这个ID,就给服务端一个回复IF,消息发送出去,没有回复,THEN一直循环发 ...

  2. 查看进程lsof

    查看8000端口 lsof -i :8000 杀死进程 pkill -ns <pid>

  3. Vue+webpack+echarts+jQuery=demo

    需要的插件: "dependencies": { "bootstrap": "^3.3.7", "echarts": & ...

  4. Codeforces Round #275 (Div. 2)-A. Counterexample

    http://codeforces.com/contest/483/problem/A A. Counterexample time limit per test 1 second memory li ...

  5. C++ static关键字

    一.面向过程中的static 1.修饰全局变量(静态全局变量) (1)静态全局变量在全局数据区分配内存: (2)未经初始化的静态全局变量会被程序自动初始化为0: (3)静态全局变量在申明它的整个文件是 ...

  6. 第2节 azkaban调度:1、azkaban的调度任务使用

    2.4 Azkaban实战 Azkaba内置的任务类型支持command.java Command类型单一job示例 创建job描述文件 创建文本文件,更改名称为mycommand.job 注意后缀. ...

  7. Bootstrap历练实例:基本按钮组

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  8. Bootstrap 网页乱码

    问题:今天早上在实践bootstrap的时候,用EditPlus写代码,标签中包含了中文.在浏览器解析的时候中文部分生成的乱码.但是网页部分已经声明了使用utf-8的编码方式. 解决:网页字体正常显示 ...

  9. shell脚本,awk常见初始化变量的题目。

    文件 内容如下 clone=line1gb=line1gi=line1lib=line1gb=line2gi=line2lib=line2clone=line3gb=line3gi=line3lib= ...

  10. base64类

    public class Base64{ /** * how we separate lines, e.g. \n, \r\n, \r etc. */ private String lineSepar ...