Leetcode 349. 两个数组的交集 By Python
2024-08-25 18:19:21
给定两个数组,编写一个函数来计算它们的交集。
示例 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))
最新文章
- Java EE之一个表单两个按钮响应不同界面(登录与注册)
- java 文件上传
- linux基础学习
- Swift的基本类型和流程控制
- HDU 5784 (计算几何)
- javaSE第二十二天
- Genymotion与本地电脑共享文件夹的方法
- [转贴]Windows下gSoap交叉编译环境的搭建
- mysql查询分组归类函数-group_concat,通常与group_by一起使用
- 求最长连续公共子序列 POJ 3080
- ES6解构赋值详解
- luogu P3373 【模板】线段树 2
- 十、 Spring Boot Shiro 权限管理
- 【一天一道LeetCode】#43. Multiply Strings
- 第三十一节,目标检测算法之 Faster R-CNN算法详解
- Python——特殊属性与方法
- vb用createprocess启动其他应用程序
- sqlServer 查询表中31到40的记录,考虑id不连续的情况
- Office - Excel 2013
- springmvc web.xml配置之 -- SpringMVC IOC容器初始化
热门文章
- redis的spring的xml配置
- 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 ).
- tomcat one connection one thread one request one thread
- Swagger UI 用法
- Windows10下安装VMware虚拟机并搭建CentOS系统环境
- md5加密通过URL传给后台
- yolo buffer is too small for requested array
- 关于windows注册表
- html 引入页面公共部分(header、footer)
- 谈谈对C#中反射的一些理解和认识(上)