Leetcode 349. 两个数组的交集 By Python
给定两个数组,编写一个函数来计算它们的交集。
示例 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))
Leetcode 349. 两个数组的交集 By Python的更多相关文章
- Java实现 LeetCode 349 两个数组的交集
349. 两个数组的交集 给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2] 示例 2: 输入: num ...
- Leetcode 350.两个数组的交集|| By Python
给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入: nums1 = [4,9,5 ...
- 前端与算法 leetcode 350. 两个数组的交集 II
目录 # 前端与算法 leetcode 350. 两个数组的交集 II 题目描述 概要 提示 解析 解法一:哈希表 解法二:双指针 解法三:暴力法 算法 # 前端与算法 leetcode 350. 两 ...
- Java实现 LeetCode 350 两个数组的交集 II(二)
350. 两个数组的交集 II 给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入 ...
- leetcode NO.349 两个数组的交集 (python实现)
来源 https://leetcode-cn.com/problems/intersection-of-two-arrays/ 题目描述 给定两个数组,写一个函数来计算它们的交集. 例子: 给定 nu ...
- python(leetcode)-350两个数组的交集
给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入: nums1 = [4,9,5 ...
- 领扣(LeetCode)两个数组的交集II 个人题解
给定两个数组,编写一个函数来计算它们的交集. 示例 1: 输入: nums1 = [1,2,2,1], nums2 = [2,2] 输出: [2,2] 示例 2: 输入: nums1 = [4,9,5 ...
- LeetCode 350: 两个数组的交集 II Intersection of Two Arrays II
题目: 给定两个数组,编写一个函数来计算它们的交集. Given two arrays, write a function to compute their intersection. 示例 1: 输 ...
- [LeetCode] 350. 两个数组的交集 II intersection-of-two-arrays-ii(排序)
思路: 先找到set的交集,然后分别计算交集中的每个元素在两个原始数组中出现的最小次数. class Solution(object): def intersect(self, nums1, nums ...
随机推荐
- Windows之文件夹中打开PowerShell
Windows之文件夹中打开PowerShell 为了解决Windows中在某个路径下使用PowerShell,而不是使用传统的cd命令切换过去,具体做法如下: 方法一 打开文件夹 在文件夹的内容区按 ...
- Vector源码分析
Vector与ArrayList底层实现基本类似,底层都是用数组实现的,最大的不同是Vector是线程安全的.ArrayList源码分析请参考ArrayList源码分析 一.源码分析 基于jdk1.7 ...
- 【问题解决方案】The MathType Dll cannot be found 问题解决方案
先贴几个可能的方法: 如何解决MathPage.wll或MathType.dll文件找不到问题 The MathType Dll cannot be found 问题解决办法 如果还搞不定,试试卸载重 ...
- spring datasource jdbc 密码 加解密
spring datasource 密码加密后运行时解密的解决办法 - 一号门-程序员的工作,程序员的生活(java,python,delphi实战)http://www.yihaomen.com/a ...
- HowTos/Virtualization/VirtualBox - CentOS Wiki
https://wiki.centos.org/HowTos/Virtualization/VirtualBox
- winform使用相关
1.回车键触发按钮点击事件——回车登录 设置窗体的AccessButton属性 2.密码框样式设置 设置PasswordChar为想要的密码显示的样式,如* 3.设置窗口居中 设置StartPosi ...
- 关于vagrant一个虚拟机搭建多个项目配置(总结)
问题1:执行vagrant status命令,报错,没有找到命令,翻译:“vargrant bash命令没有找到.” 解答:因为在/home目录中,所有无法执行该命令,需要切换到外部进行执行 问题2: ...
- C# Note33: 总结C# 6.0/7.0 新特性
先注明,本文主体参考自:C# 6.0新特性 目前代码中使用了很多C#6.0的新特性,下面以Point类来做相关叙述: public class Point { public int X { get; ...
- Spring boot + mybatis + orcale实战(干货)
废话少说,直接上步骤: 第一步:安装好IDEA(此处省略) 第二步:在IDEA新建springboot工程 第三步:在springboot工程的pom.xml添加oracle和mybait依赖 < ...
- MySQL客户端工具及SQL
一.客户端命令介绍 mysql mysqladmin mysqldump mysql 1.用于数据库的连接管理 2. mysqladmin 1. 2. mysqldump 1. 2.