leetcode笔记10 Intersection of Two Arrays(求交集)
问题描述:
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(求交集)的更多相关文章
- 【一天一道LeetCode】#350. Intersection of Two Arrays II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- 【leetcode】350. Intersection of Two Arrays II
problem 350. Intersection of Two Arrays II 不是特别明白这道题的意思,例子不够说明问题: 是按顺序把相同的元素保存下来,还是排序,但是第二个例子没有重复... ...
- Intersection of Two Arrays(交集)
来源:https://leetcode.com/problems/intersection-of-two-arrays Given two arrays, write a function to co ...
- 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 ...
- 【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
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- LeetCode算法题-Intersection of Two Arrays(Java实现-四种解法)
这是悦乐书的第207次更新,第219篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第75题(顺位题号是349).给定两个数组,编写一个函数来计算它们的交集.例如: 输入: ...
- 【LeetCode】349. Intersection of Two Arrays 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:Java解法,HashSet 方法二:Pyt ...
- 【leetcode❤python】Intersection of Two Arrays
#-*- coding: UTF-8 -*- #求两个集合的交集class Solution(object): def intersection(self, nums1, nums2): ...
随机推荐
- CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?
http://stackoverflow.com/questions/14042755/coreanimation-confusion-catransaction-vs-catransition-vs ...
- 时钟系统与UART
关于时钟设置原理: 关于如何设置系统时钟的思路. 其中锁定时间需要一个寄存器,PLL需要一个寄存器(MPLLCL),分频还需要一个寄存器,总计三个寄存器.步骤如下: 1. 上电后,FCLK=Fin 2 ...
- POJ 1651 Multiplication Puzzle(类似矩阵连乘 区间dp)
传送门:http://poj.org/problem?id=1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K T ...
- 听说玩JAVA,必须过JDK这关?
JDK是什么?JRE是什么?JDK和JRE的区别? Java Runtime Environment (JRE) 包含: Java虚拟机.库函数.运行Java应用程序和Applet所必须文件 Java ...
- iOS11.2-11.3.1进行越狱及问题
设备环境:Electra.iOS11.13.1 PS:Electra最新版本进行越狱只支持11.14以下的版本.同时这是不完美越狱,每次重启手机都需要重新越狱,最后,由于Electra版本推出仓促,一 ...
- Webstorm设置代码提示
下载路径: https://github.com/virtoolswebplayer/ReactNative-LiveTemplate 本插件可以配合Webstorm设置代码提示. Mac下安装 We ...
- 学习笔记(3)centos7 下安装RabbitMQ
centos7 安装RabbitMQ 安装erlang 因为RabbitMQ由ERLANG实现,所以需要先安装erlang.可以从https://www.erlang-solutions.com/re ...
- DB数据源之SpringBoot+MyBatis踏坑过程(五)手动使用Hikari连接池
DB数据源之SpringBoot+MyBatis踏坑过程(五)手动使用Hikari连接池 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之SpringBoot+Mybatis踏坑 ...
- 用RestTemplate调取接口,取得返回数据,携带header,动态拼接url ,动态参数
记录我自己的工作 get 请求 ,携带 请求头 header (token) url 根据参数 动态拼接 参数 放入 map 动态拼接 private String lclUrl = &quo ...
- tornado用户指引(三)------tornado协程使用和原理(二)
Python3.5 async和await async和await是python3.5引入的2个新的关键字(用这两个关键字编写的函数也称之为"原生协程"). 从tornado4. ...