只需要用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. MySQL select * 和把所有的字段都列出来,哪个效率更高?

    MySQL select * 和把所有的字段都列出来,哪个效率更高 答案是:如何,都不推荐使用 SELECT * FROM (1)SELECT *,需要数据库先 Query Table Metadat ...

  2. ftp - Internet 文件传输程序 (file transfer program)

    概述 (SYNOPSIS) ftp [-pinegvd ] [host ] pftp [-inegvd ] [host ] 说明 (DESCRIPTION) 用户通过 Ftp 这个程序来使用 Inte ...

  3. nginx “403 Forbidden” 错误 解决方法

    错误的原因是缺少index.html或者index.php文件,就是配置文件中index index.html index.htm这行中的指定的文件 只需要配置时加一句  index  index.h ...

  4. JS中的事件、事件冒泡和事件捕获、事件委托

    https://www.cnblogs.com/diver-blogs/p/5649270.html https://www.cnblogs.com/Chen-XiaoJun/p/6210987.ht ...

  5. Easier Done Than Said?(应用到的知识)

    memset(b,0,sizeof(b)) 对于大块儿内存的分配,例如int arr[100];定义了数组arr,包含100个元素,如果你写成int arr[100]=0;想将数组全部内容初始化为0, ...

  6. python_109_切片补充和list函数

    #切片补充 a=[1,2,3,4,5,6,7,8] print(a[::2])#隔一个取一个元素 [1, 3, 5, 7] print(a[::-1])#将列表或元祖颠倒过来 [8, 7, 6, 5, ...

  7. ewebeditor上传文件大小

    做项目大家都少不了要跟html在线编辑器打交道,这里我把我的一些使用经验及遇到的问题发出来和大家交流一下. Ewebeditor使用说明:一.部署方式:1.直接把压缩目录中的文件拷贝到您的网站发布目录 ...

  8. 17条 Swift 最佳实践规范

    本文由CocoaChina译者小袋子(博客)翻译自schwa的github主页原文作者:schwa 这是一篇 Swift 软件开发的最佳实践教程. 前言 这篇文章是我根据在 SwiftGraphics ...

  9. MacBook Pro休眠掉电、耗电量大问题解决方案

    1.前言 最近我的2015mbpMacBook Pro (Retina, 13-inch, early 2015)更新完10.14系统后,发现休眠待机一晚上后能掉5%电,白天待机4-5小时又掉了8%. ...

  10. 剑指Offer(书):链表中环的入口节点

    题目:给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null. public ListNode EntryNodeOfLoop(ListNode pHead) { //第一步,查找是 ...