【leetcode❤python】350. Intersection of Two Arrays II
#-*- 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的更多相关文章
- [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】350. Intersection of Two Arrays II
problem 350. Intersection of Two Arrays II 不是特别明白这道题的意思,例子不够说明问题: 是按顺序把相同的元素保存下来,还是排序,但是第二个例子没有重复... ...
- 【一天一道LeetCode】#350. Intersection of Two Arrays II
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...
- 【LeetCode】350. Intersection of Two Arrays II 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 Java排序+双指针 Python排序+双指针 Python解 ...
- 【leetcode❤python】 160. Intersection of Two Linked Lists
#-*- coding: UTF-8 -*- #两种方法#方法1:#计算出A和B两个链表的长度分别为m.n;#长度长的链表先走m-n步,之后再一次遍历寻找#方法2:#先走到一个链表的尾部,从尾部开始走 ...
- [LeetCode] 349 Intersection of Two Arrays && 350 Intersection of Two Arrays II
这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/in ...
- 26. leetcode 350. Intersection of Two Arrays II
350. Intersection of Two Arrays II Given two arrays, write a function to compute their intersection. ...
- 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 ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
随机推荐
- oracle热备份
1:热备份: SHUTDOWN IMMEDIATE; STARTUP MOUNT; alter database archivelog; --ALTER SYSTEM SET LOG_ARCHIVE_ ...
- 夺命雷公狗---DEDECMS----8dedecms干掉首页和-文档页-栏目页的页面的广告
我们首先来将首页生成静态页面,如下图所示: 成功后,如下显示: 如果成功后则在文件夹下多了一个index.html的文件.. 我们的首页静态页面是通过模版文件生成,所以我们只需要把模版文件的广告标签删 ...
- Bug测试报告--俄罗斯方块--新蜂
项目名:俄罗斯方块 组名:新蜂 测试者:韩媛媛(nice!团队) 用户需求规格说明书URL:http://www.cnblogs.com/Boxer1994/p/6084035.html 组长博客UR ...
- Entity Framework 无法对没有主键的视图映射实体的解决办法
我们在使用Entity Framework的时候经常会把数据库中的某一个视图映射为EF的实体,但是如果数据库视图中的列没有包含表的主键列,EF会报出警告说视图没有主键,导致视图映射为实体失败,错误如下 ...
- OpenStack fuel-web不可用解决办法
Contents [hide] 1 为增加一台计算节点 2 磁盘清空 3 启动占用8001端口的进程 4 启动占用5432端口的进程 为增加一台计算节点 打开fuel-web,发现无法打开,弹出ngi ...
- WM_SETFOCUS和WM_KILLFOCUS、WM_GETDLGCODE、CM_ENTER...
procedure WMSetFocus (var Message: TWMSetFocus); message WM_SETFOCUS; //获得焦点 procedure WMKillFocus ( ...
- PL/SQL快捷键
F8 执行所选中的SQL语句 当光标在sql语句末尾/开头 时 按Shift Home /Shift End 选中该语句
- Notepad++编辑Pyhton文件的自动缩进的问题(图文)
转自:http://www.xuebuyuan.com/1102224.html 这个问题一直困扰我很久,Python对缩进很敏感,一般建议缩进用空格,而 Notepad++的自动缩进是用的TAB,g ...
- linux内核栈用户栈切换【转】
转自:http://www.kerneltravel.net/kernel-book/%E7%AC%AC%E5%9B%9B%E7%AB%A0%20%E8%BF%9B%E7%A8%8B%E6%8F%8F ...
- 创建sh文件
创建sh文件 #/bin/bash v_file=$ v_type=$ v_desc=$ touch $v_file echo '#================================== ...