问题描述:

Given two arrays, write a function to compute their intersection.

Example:
Given nums1 = [1, 2, 2, 1]nums2 = [2, 2], return [2].

Note:

  • Each element in the result must be unique.
  • The result can be in any order.

my answer:

思路:

遍历nums1里的元素,看nums2里是否存在,如果存在且没有在num里出现过,则添加到num,最后返回num

重点问题:

1 忘记考虑nums1为None的情况

2 在第二个if 下使用set(num)总是报错,还没有明白为什么

leetcode笔记10 Intersection of Two Arrays(求交集)的更多相关文章

  1. 【一天一道LeetCode】#350. Intersection of Two Arrays II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  2. 【leetcode】350. Intersection of Two Arrays II

    problem 350. Intersection of Two Arrays II 不是特别明白这道题的意思,例子不够说明问题: 是按顺序把相同的元素保存下来,还是排序,但是第二个例子没有重复... ...

  3. Intersection of Two Arrays(交集)

    来源:https://leetcode.com/problems/intersection-of-two-arrays Given two arrays, write a function to co ...

  4. LeetCode:4_Median of Two Sorted Arrays | 求两个排序数组的中位数 | Hard

    题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  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

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  7. LeetCode算法题-Intersection of Two Arrays(Java实现-四种解法)

    这是悦乐书的第207次更新,第219篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第75题(顺位题号是349).给定两个数组,编写一个函数来计算它们的交集.例如: 输入: ...

  8. 【LeetCode】349. Intersection of Two Arrays 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:Java解法,HashSet 方法二:Pyt ...

  9. 【leetcode❤python】Intersection of Two Arrays

    #-*- coding: UTF-8 -*- #求两个集合的交集class Solution(object):    def intersection(self, nums1, nums2):     ...

随机推荐

  1. 用SQL实现的BASE64加密及解密函数(SQL2005以上有效)

    CREATE FUNCTION [dbo].[f_base64_encode] (@bin varbinary(max)) returns varchar(max) as begin return c ...

  2. Linux学习总结(九)-源码包和rpm包安装

    一.源码包安装 通常办法是安装三部曲:./configuremakemake install但是具体还要根据包里面的帮助文档操作./configure --help 可以查看可以带什么参数,比如--p ...

  3. 理解JavaScript数据类型

    JavaScript有5种基本数据类型: 数值(number):整数和小数(比如1和3.14) 字符串(string):字符组成的文本(比如"Hello World") 布尔值(b ...

  4. hadoop-2.2.0 HA配置

    采用的是4台真实机器: namenode:qzhong  node27 datanode:qzhong node27 node100 node101 操作系统环境:qzhong(Ubuntu-14.0 ...

  5. hadoop-1.2.1分布式配置启动问题

    关键配置(core-site.xml 和hdfs-site.xml)(这里只是针对与HDFS,没有启动MapReduce): core-site.xml <?xml version=" ...

  6. 关于H5 移动端css 文本超出时省略号 失效的问题

    之前写代码的时候遇到一个问题,就是用了下面这段css代码来让文字超出范围隐藏并显示省略号. overflow: hidden; text-overflow: ellipsis; display: -w ...

  7. 常见的springmvc、SpringBoot的注解

    springMvc的常用注解 : @Controller :用于标记在一个类上,使用它标记的类就是一个springmcv Controller对象,分发处理器将会扫描使用了该注解 的类的方法,并检测该 ...

  8. Centos7单网卡带VLAN多IP配置

    1.需要使用到vconfig软件,首先yum安装vconfig: 使用指令yum install vconfig:(若是本机找不到vconfig安装包,可以通过其他centos7安装yum-utils ...

  9. Jewels and Stones

    题目如下 You're given strings J representing the types of stones that are jewels, and S representing the ...

  10. 如何在tornado中以异步的方式调用同步函数

    问题 如何在tornado的coroutine中调用同步阻塞的函数 解决方案 使用python内置标准库的concurrent.futures.ThreadPoolExecutor和tornado.c ...