[LeetCode&Python] Problem 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.
Example 1:
Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2]
Example 2:
Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
Output: [9,4]
Note:
- Each element in the result must be unique.
- The result can be in any order.
class Solution(object):
def intersection(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
return list(set(nums1).intersection(set(nums2)))
[LeetCode&Python] Problem 349. Intersection of Two Arrays的更多相关文章
- [LeetCode&Python] Problem 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- 【leetcode❤python】350. Intersection of Two Arrays II
#-*- coding: UTF-8 -*- class Solution(object): def intersect(self, nums1, nums2): ...
- [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II
这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...
- LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List
283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...
- [LeetCode] 349. Intersection of Two Arrays 两个数组相交
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- 【LeetCode】349. Intersection of Two Arrays 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:Java解法,HashSet 方法二:Pyt ...
- 【一天一道LeetCode】#349. Intersection of Two Arrays
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- LeetCode 349 Intersection of Two Arrays 解题报告
题目要求 Given two arrays, write a function to compute their intersection. 题目分析及思路 给定两个数组,要求得到它们之中共同拥有的元 ...
- LeetCode 349. Intersection of Two Arrays (两个数组的相交)
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
随机推荐
- vue 中router.go、router.push和router.replace的区别
router.go(n) 这个方法的参数是一个整数,意思是在 history 记录中向前或者后退多少步,类似 window.history.go(n) router.push(location) 想要 ...
- 从线程模型的角度看Netty的高性能
转载:Netty(二) 从线程模型的角度看 Netty 为什么是高性能的? 传统 IO 在 Netty 以及 NIO 出现之前,我们写 IO 应用其实用的都是用 java.io.* 下所提供的包. 比 ...
- 通过配置hosts.allow和hosts.deny文件允许或禁止ssh或telnet操作
1.登录主机,如果是普通账户先切换至root账号 su root 2.编缉/etc/hosts.allow文件 vi /etc/hosts.allow 允许内容 书写格式(改成自自需要的IP或IP段) ...
- MySQL设置白名单教程
1 登录mysql mysql -h host -u username -p password 2 切换至mysql库 use mysql; 3 查看当前允许登录IP及用户 select Host,U ...
- date命令说明
基本使用格式: date [-d "time-to-display"] +"format-to-display" -d指定要显示的时间,如果不指定默认为当前时间 ...
- python(2)之列表
列表的使用 names=["zhangyang","liming",["sese","popo"],"xiao ...
- 使用C#开发数据库应用程序
第一章 用Hello ACCP.NET快速热身(一) 1-1.进入C#世界 a.第一个C#程序 (1)新建项目[项目:project] (2)生成解决方案[生成:build,解决方案:solution ...
- nyoj-0737-石子合并(dp)
nyoj-0737-石子合并 题意:有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆.合并的过程只能每次将相邻的两堆石子堆成一堆,每次合并花费的代价为这两堆石子的和,经过N-1次合并 ...
- Mac上搭建nginx教程
1.安装Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/in ...
- do_bootrk
1. LMB (logical memory blocks) lmb为uboot下的一种内存管理机制,用于管理镜像的内存.lmb所记录的内存信息最终会传递给kernel.在/include/lmb.h ...