#-*- coding: UTF-8 -*-
#求两个集合的交集
class Solution(object):
    def intersection(self, nums1, nums2):
       resultList=list(set(nums1).intersection(set(nums2)))
       return resultList

sol=Solution()
print sol.intersection(nums1=[1, 2, 2, 1], nums2=[2,2])

【leetcode❤python】Intersection of Two Arrays的更多相关文章

  1. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  2. 【leetcode❤python】350. Intersection of Two Arrays II

    #-*- coding: UTF-8 -*- class Solution(object):    def intersect(self, nums1, nums2):                ...

  3. 【leetcode❤python】 160. Intersection of Two Linked Lists

    #-*- coding: UTF-8 -*- #两种方法#方法1:#计算出A和B两个链表的长度分别为m.n;#长度长的链表先走m-n步,之后再一次遍历寻找#方法2:#先走到一个链表的尾部,从尾部开始走 ...

  4. 【leetcode❤python】 1. Two Sum

    #-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object):    def twoSum(self, nums, target):  ...

  5. 【leetcode❤python】 58. Length of Last Word

    #-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object):   ...

  6. 【leetcode❤python】 8. String to Integer (atoi)

    #-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...

  7. 【LeetCode 160】Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  8. 【leetcode❤python】 165. Compare Version Numbers

    #-*- coding: UTF-8 -*-class Solution(object):    def compareVersion(self, version1, version2):       ...

  9. 【leetcode❤python】 168. Excel Sheet Column Title

    class Solution(object):    def convertToTitle(self, n):        """        :type n: in ...

随机推荐

  1. PAT乙级 1017. A除以B (20)

    1017. A除以B (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求计算A/B,其中A是不超过 ...

  2. zabbix监控phpfpm

    php-fpm status详解 pool – fpm池子名称,大多数为wwwprocess manager – 进程管理方式,值:static, dynamic or ondemand. dynam ...

  3. NEON简介【转】

    转自:http://blog.csdn.net/fengbingchun/article/details/38020265 版权声明:本文为博主原创文章,未经博主允许不得转载. “ARM Advanc ...

  4. 【转载】使用barman备份PostgreSQL

    什么是barman Barman (备份和恢复管理器) 是 PostgreSQL 数据库服务器中非常方便的备份和恢复工具,允许远程备份多个服务器,允许从一个备份集中一个命令就恢复数据库.同时还可以对多 ...

  5. Effective C++第三遍

    试图调用private的copy或赋值函数是编译期错误,而调用没有具体定义的函数则是连接期错误. 以对象管理资源:智能指针RAII(资源获取立即初始化)后都是对象,但有时候,比如(API的)函数参数要 ...

  6. js作用域链与this

    this的绑定与function和对象的定义位置无关,是由函数调用时的执行环境所决定的. scope chain是由函数定义时的位置决定的与函数调用时的执行环境无关.

  7. ACM题目————放苹果

    Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. Input 第一行是测试数据的数目t(0 ...

  8. stl map底层之红黑树插入步骤详解与代码实现

    转载注明出处:http://blog.csdn.net/mxway/article/details/29216199 本篇文章并没有详细的讲解红黑树各方面的知识,只是以图形的方式对红黑树插入节点需要进 ...

  9. css select 样式列表-----另一种样式列表

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org ...

  10. jqeury之平移轮播

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...