[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] ...
随机推荐
- SpringMVC中JSP页面显示为源码
@RequestMapping(value = "login") public ModelAndView login(ModelAndView mav) throws Except ...
- python logs
# -*- coding: utf-8 -*-import loggingimport sysimport osimport xlrdfrom UtilAzxu import Properties# ...
- memory prefix mini mono multi out _m 5
1● mini 小 迷你 2● mono 单一 ,单 3● multi 多
- IO库----IO类,文件输入输出,string流
一.IO类 1.IO库类型和头文件表: 头文件 类型 iostream istream,wistream 从流读取数据 ostream,wostream 向流写入数据 iostream,wiostre ...
- laravel的日志服务
日志服务使用: $app=app(); $log=$app->make('log'); $log->info('post_index',['data'=>'this is post ...
- MAVEN 自定义骨架
1)根据原由的骨架先创建出一个骨架模板,例如创建一个web框架可以先通过命令 mvn archetype:generate -DarchetypeCatalog=internal 创建出一个web的 ...
- Java单例模式《二》懒汉式
package com.study.mode; /** * 单例模式: 懒汉式,需要的时候创建. * @ClassName: SingleBean2 * @author BlueLake * @dat ...
- day7-python打开文件方式
文件操作 对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 基本操作 import codecs #主要用来解决乱码问题 f = codecs.open('1. ...
- 《Python》re模块补充、异常处理
一.re模块 1.match方法 import re # match 验证用户输入的内容 ret = re.match('\d+', 'hhoi2342ho12ioh11') print(ret) # ...
- JavaScript简介及作用
JavaScript是一门脚本语言,是可以插入HTML页面的编程代码,插入HTML以后可以由所有现代浏览器运行 一.写如html输出 <body> <script> docum ...