#-*- coding: UTF-8 -*-
class Solution(object):
    def intersect(self, nums1, nums2):
        
        if len(nums1)<len(nums2):
            tmp=nums1
            nums1=nums2
            nums2=tmp
       
        tmpdic={}
       
        for num in nums1:
            tmpdic[num]=tmpdic[num]+1 if num in tmpdic else 1
        
        commonList=[]
        for num in nums2:
 
            if tmpdic.get(num)>None and tmpdic.get(num)>=1:
                
                commonList.append(num)
                
                tmpdic[num]=tmpdic.get(num)-1
      
        return commonList
            
sol=Solution()
print sol.intersect(nums1=[1,1,1], nums2=[1,1])

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

  1. [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 ...

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

    problem 350. Intersection of Two Arrays II 不是特别明白这道题的意思,例子不够说明问题: 是按顺序把相同的元素保存下来,还是排序,但是第二个例子没有重复... ...

  3. 【一天一道LeetCode】#350. Intersection of Two Arrays II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  4. 【LeetCode】350. Intersection of Two Arrays II 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 Java排序+双指针 Python排序+双指针 Python解 ...

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

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

  6. [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II

    这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...

  7. 26. leetcode 350. Intersection of Two Arrays II

    350. Intersection of Two Arrays II Given two arrays, write a function to compute their intersection. ...

  8. LeetCode Javascript实现 169. Majority Element 217. Contains Duplicate(两个对象比较是否相等时,如果都指向同一个对象,a==b才是true)350. Intersection of Two Arrays II

    169. Majority Element /** * @param {number[]} nums * @return {number} */ var majorityElement = funct ...

  9. 【leetcode❤python】Sum Of Two Number

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

随机推荐

  1. oracle的会话(session)

    会话(session)是oracle服务器对数据库连接用户记录的一种手段. oracle提供了v_$session的视图存储当前数据库的会话,查询时用v_$session 或v$session sql ...

  2. 夺命雷公狗ThinkPHP项目之----企业网站10之栏目的编辑完善(无限极分类的完成)

    我们编辑首先就要考虑将下拉框效果实现出来,然后再进行下一步操作: 我们用到了Model层的操作,在第8讲里面其实已经写好了catTree方法,控制器如下所示: 然后在列表页然他变量进行输出 然后开始通 ...

  3. 怎么开启PHP 的错误提示?

    怎么开启PHP 的错误提示?   在php.ini 修改error_reporting = E_ALL & ~E_NOTICEdisplay_errors = On重启apache服务器在运行 ...

  4. Delphi 中将一些 Dll等生成资源文件打包成一个独立的EXE程序方法步骤

    资源文件一般为扩展名为res的文件,其自带的资源编译工具BRCC32.EXE(位于/Delphi/BIN目录下) 1.编写rc脚本文本 用记事本或其它文本编辑器编写一个扩展名为rc的文件,格式分别为在 ...

  5. <c:if>条件判断 和 取值做乘法运算

    http://www.yiibai.com/jstl/jstl_core_if_tag.html <td> ${log.etdhHandleTime }<span>  < ...

  6. JSP/Servlet 中的汉字编码问题

    JSP/Servlet 中的汉字编码问题 1.问题的起源 每个国家(或区域)都规定了计算机信息交换用的字符编码集,如美国的 ASCII,中国的 GB2312 -80,日本的 JIS 等,作为该国家/区 ...

  7. Redis 转

    Redis 简介 Redis实践 Redis命令总结

  8. linux乱码

    修改系统变量: export LANG=en

  9. PHP使用PHPExcel删除Excel单元格指定列的方法是怎样

    有一个系统仅公司内部和外部经销商使用,在一个导出功能中公司内部员工跟外部经销商导出的列是不一样的(某些数据是不能提供给经销商的)因为导出的数据都是一样的(某些列外数据外部没有)因此并没有单独处理,而是 ...

  10. YTU 2973: C语言习题5.25--文件操作2

    2973: C语言习题5.25--文件操作2 时间限制: 1 Sec  内存限制: 128 MB 提交: 242  解决: 105 题目描述 文本文件score.dic 中存储了n名学生的信息(班级编 ...