给定两个数组,编写一个函数来计算它们的交集。

示例 1:

输入: nums1 = [1,2,2,1], nums2 = [2,2]
输出: [2]

示例 2:

输入: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
输出: [9,4]

思路

没什么好说的,用set,再用交运算就好了

代码

class Solution:
def intersection(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
return list(set(nums1) & set(nums2))

最新文章

  1. Java EE之一个表单两个按钮响应不同界面(登录与注册)
  2. java 文件上传
  3. linux基础学习
  4. Swift的基本类型和流程控制
  5. HDU 5784 (计算几何)
  6. javaSE第二十二天
  7. Genymotion与本地电脑共享文件夹的方法
  8. [转贴]Windows下gSoap交叉编译环境的搭建
  9. mysql查询分组归类函数-group_concat,通常与group_by一起使用
  10. 求最长连续公共子序列 POJ 3080
  11. ES6解构赋值详解
  12. luogu P3373 【模板】线段树 2
  13. 十、 Spring Boot Shiro 权限管理
  14. 【一天一道LeetCode】#43. Multiply Strings
  15. 第三十一节,目标检测算法之 Faster R-CNN算法详解
  16. Python——特殊属性与方法
  17. vb用createprocess启动其他应用程序
  18. sqlServer 查询表中31到40的记录,考虑id不连续的情况
  19. Office - Excel 2013
  20. springmvc web.xml配置之 -- SpringMVC IOC容器初始化

热门文章

  1. redis的spring的xml配置
  2. No enclosing instance of type is accessible. Must qualify the allocation with an enclosing instance of type LeadRestControllerTest (e.g. x.new A() where x is an instance of ).
  3. tomcat one connection one thread one request one thread
  4. Swagger UI 用法
  5. Windows10下安装VMware虚拟机并搭建CentOS系统环境
  6. md5加密通过URL传给后台
  7. yolo buffer is too small for requested array
  8. 关于windows注册表
  9. html 引入页面公共部分(header、footer)
  10. 谈谈对C#中反射的一些理解和认识(上)