【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 ...
随机推荐
- 夺命雷公狗jquery---5可见选择器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- JSP-09-使用EL显示数据
目的:为了使JSP写起来更加简单. 9.1 EL表达式 ${EL表达式} : ${unsername} 操作符: “. ”操作符: 用来访问对象的属性 ${news.title} “[ ...
- C++头文件为什么要加#ifndef #define #endif
#ifndef 在头文件中的作用 在一个大的软件工程里面,可能会有多个文件同时包含一个头文件,当这些文件编译链接成一个可执行文件时 ,就会出现大量“重定义”的错误.在头文件中实用#ifndef #de ...
- Android利用数据库传送数据
---恢复内容开始--- 一.建表 //通过SQLiteDatabase 创建数据库stu.db3 final SQLiteDatabase db = SQLiteDatabase.openOrCre ...
- Android 多线程通信 访问网络
package org.rongguang.testthread; import android.app.Activity; import android.os.Bundle; import andr ...
- SQL中的连接可以分为内连接,外连接,以及交叉连接 。
SQL中的连接可以分为内连接,外连接,以及交叉连接 . 1. 交叉连接CROSS JOIN 如果不带WHERE条件子句,它将会返回被连接的两个表的笛卡尔积,返回结果的行数等于两个表行数的乘积: 举例, ...
- Temporary TempDB Tables [AX 2012]
Temporary TempDB Tables [AX 2012] 1 out of 4 rated this helpful - Rate this topic Updated: November ...
- 如何为github上的项目添加gif效果图
一.制作gif图片 如何制作可以参考: http://www.jianshu.com/p/27ec6375b8ab?utm_campaign=maleskine&utm_content=not ...
- sass初步认识3
sass的混合器是对大段的样式代码进行命名,定义为混合器,以便被多次引用.混合器的格式为:“@mixin 样式名称{样式代码}”:调用混合器的格式为:“@include 样式名称”.例:@minin ...
- python怎么装模块
windows下 最简单的方法: File---Settings--Project ---Project Interpreter 下----点击 +号,输入你需要安装的模块名,点击Install P ...