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): ...
随机推荐
- virtualbox 安装 mac os x lion 10.7实现全屏显示!
1. 启动Virtual Box虚拟机,在虚拟机里编辑 /Library/Preferences/SystemConfiguration/com.apple.Boot.plist,找到 <dic ...
- Motrix 全平台多功能下载工具[Windows、macOS、Linux]
Motrix的界面很朴素,使用起来其实也很方便.点击左侧的「+」图标就可以添加下载任务,跟其他的下载工具没什么区别.暂停.恢复.查看.复制,这些功能都不缺.界面也挺好看的,下载速度还会提示在图标的角标 ...
- 关于PHP中的 serialize () 和 unserialize () 的使用(即关于PHP中的值与已存储的表示的相互转换)
有时,我们会碰到这样的数据(字符串) a:3:{i:0;s:44:"/Uploads/images/2017-07-21/5971a9a08ad57.png";i:1;s:44:& ...
- windows下如何安装pip以及如何查看pip是否已经安装成功?
最近刚学习python,发现很多关于安装以及查看pip是否安装成的例子都比较老,不太适合于现在(python 3.6 )因此,下一个入门级别的教程. 0:首先如何安装python我就不做介绍了. 1: ...
- JAVA揭竿而起总要有名号
古代揭竿而起总要有个响亮的名号,这可不是随便的哦,比如 苍天已死,黄天当立... 玩JAVA里面形形色色的名字,都是有套路的,至于名字怎么起法,那得问问标识符 标识符 用作给变量.类和方法命名.注意 ...
- ObjC之RunTime(下)
之前通过学习官方文档对runtime有了初步的认识,接下来就要研究学习runtime到底能用在哪些地方,能如何改进我们的程序. 本文也可以从icocoa浏览. Swizzling Swizzling可 ...
- UICollectionView reloadItemsAtIndexPaths时 报错
在刷新下载进度时 Xcode报错误: Terminating app due to uncaught exception 'NSInternalInconsistencyException', rea ...
- JavaScript高级程序设计(复制变量值、传递参数)
复制变量值 一个变量向另一个变量复制基本类型值和引用类型值时,是存在不同的. 一个变量向另一个变量复制基本类型的值,会在变量的对象上创建一个新值,然后把该值复制到为新变量分配的位置上. var num ...
- Python豆瓣源
pip install -i https://pypi.doubanio.com/simple/ xxxx
- jQuery获取Select option 选择的Text和 Value
获取一组radio被选中项的值:var item = $('input[name=items][checked]').val();获取select被选中项的文本var item = $("s ...