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): ...
随机推荐
- Yii 多表关联relations
1,首先多表关联是在models/xx.php的relations里配置的.而且是互配,但有区别.格式:'VarName'=>array('RelationType', 'ClassName', ...
- Perl 修改文件内容
把test.txt文件中的字符aaa替换成bbb perl -pi -e "s/aaa/bbb/gi" test.txt 把test.txt文件中的字符aaa替换成bbb,并生成一 ...
- SSD 单发多框检测
其实现在用的最多的是faster rcnn,等下再弄项目~~~ 图像经过基础网络块,三个减半模块,每个减半模块由两个二维卷积层,加一个maxPool减半(通道数依次增加[16,32,64]) 然后是多 ...
- 禁止查看网页源代码和F12
function disableInfo() { document.onkeydown = function() { var e = window.event || arguments[0]; //屏 ...
- 原生JS写验证码
1.先创建一个一个输入框用来用户输入验证码和一个span容器用来存放系统给出的验证码和一个刷新按钮还有一个登录按钮 <input type="text" class=&quo ...
- Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】
传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...
- AngularJS 表单验证小结
注:本文所述的表单验证即AngularJS自带的表单验证,无需引入第三方的插件 一.常用的验证特性标签 1.非空 为input加入一个required属性即可,例如: <input type=& ...
- Vim插件及.vimrc文件的配置
关于Vim的配置基本是在.vimrc文件中完成的,该文件一般放在用户目录下. 今天安装了插件管理器Pathogen和python自动补全的插件pydiction,其中Pathogen需要事先创建两个文 ...
- OC实现 单向链表
需要实现一个消息队列,队列具有 FIFO 特点,即先入先出,在这里采用单向链表实现队列逻辑. 本次要实现的队列要求: 1. 节点可以存放任意类型数据 2. 线程安全 简单说明一下: 1. 创建CFNo ...
- Docker镜像浅谈
先抛出几个我在学习过程中产生的几个问题. 1. 容器镜像是什么, 和装系统时的镜像有什么关系? 2. 容器镜像的作用是什么? 3. 不同版本的ubuntu镜像有什么区别, 比如说 ubuntu:18. ...