问题描述:

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. docker-3-常用命令(上)

      帮助命令: docker version docker info docker --help 镜像命令: docker images:     列出本地主机上的镜像     各个选项说明:    ...

  2. GIS中的空间参考

    GIS一般都是研究的基于地球的某个区域,例如一个国家.省或市的情况,既然地球上都有经纬度来标识,那么直接用经纬度来标识物体的位置不可以吗?但如果应用不一样,在实际中选择的空间参考系也是不一样的.例如我 ...

  3. CentOS 7安装简介及基本操作

    计算机基本概念: 1.计算机硬件组成: 2.计算机系统结构: 3.操作系统的功能:硬件驱动.进程管理.内存管理.网络管理.安全管理.文件管理等. 4.OS通用目的的软件程序:用户<-->应 ...

  4. 如何清理Macbook垃圾文件

    如何清理Macbook垃圾文件,腾出更多硬盘空间 在Macbook使用久之后,会发现本来还富裕的硬盘,变得越来越少,尤其现在Macbook使用容量很小的固态硬盘.在此种情况下,该如何清理Macbook ...

  5. win764 ping不能用的问题

    1.某日发现,ping突然用不了了 2.百度一搜,有如下解答: 1.右击计算机点属性之后找到系统属性下的环境变量: 2.找到系统变量的"path"之后按“编辑”: 3.变量值前面的 ...

  6. java向邮箱发送消息失败!

    出现的错误如下: org.apache.commons.mail.EmailException: Sending the email to the following server failed : ...

  7. js中两个日期大小比较,获取当前日期,日期加减一天

    一.两个日期大小比较 1.日期参数格式:yyyy-mm-dd // a: 日期a, b: 日期b, flag: 返回的结果 function duibi(a, b,flag) { var arr = ...

  8. Eclipse新导入的项目中ctrl+点击指定方法名或类名没有反应,不能跳转问题

    项目没有转成java项目 解决方法:右击项目名---选择properties----点击Project Facets,这样就可以实现ctrl+左键点击跳转了. 转成java项目后会报错 解决办法:选中 ...

  9. 【CodeForces 129 B】Students and Shoelaces(拓扑排序)

    Anna and Maria are in charge of the math club for junior students. When the club gathers together, t ...

  10. zabbix基本监控各指标简解

    监控项目及使用模板 监控http和https: Template App HTTP Service     Template App HTTPS Service 监控cpu,内存,网络等: Templ ...