问题描述:

Given two arrays, write a function to compute their intersection.

Example:
Given nums1 = [1, 2, 2, 1]nums2 = [2, 2], return [2].

Note:

  • Each element in the result must be unique.
  • The result can be in any order.

my answer:

思路:

遍历nums1里的元素,看nums2里是否存在,如果存在且没有在num里出现过,则添加到num,最后返回num

重点问题:

1 忘记考虑nums1为None的情况

2 在第二个if 下使用set(num)总是报错,还没有明白为什么

leetcode笔记10 Intersection of Two Arrays(求交集)的更多相关文章

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

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

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

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

  3. Intersection of Two Arrays(交集)

    来源:https://leetcode.com/problems/intersection-of-two-arrays Given two arrays, write a function to co ...

  4. LeetCode:4_Median of Two Sorted Arrays | 求两个排序数组的中位数 | Hard

    题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  5. 【leetcode】349. Intersection of Two Arrays

    Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1 ...

  6. 【一天一道LeetCode】#349. Intersection of Two Arrays

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

  7. LeetCode算法题-Intersection of Two Arrays(Java实现-四种解法)

    这是悦乐书的第207次更新,第219篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第75题(顺位题号是349).给定两个数组,编写一个函数来计算它们的交集.例如: 输入: ...

  8. 【LeetCode】349. Intersection of Two Arrays 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:Java解法,HashSet 方法二:Pyt ...

  9. 【leetcode❤python】Intersection of Two Arrays

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

随机推荐

  1. org.openqa.selenium.WebDriverException: unknown error: missing or invalid 'entry.level'

    错误原因:chrome与chromedriver版本号不匹配,升级后即可解决

  2. 2spring注解:@Lazy,@Conditional,@import,FactoryBean接口

    大致的工程内容也来源于上一篇博文! https://www.cnblogs.com/Mrchengs/p/10108603.html 1.@Lazy懒加载 懒加载:针对单实例的 单实例bean,默认在 ...

  3. Server.xml解析

    来源 本文整理自 <Tomcat内核设计剖析>.<Tomcat结构解析> 加上自己的理解.源码来自 Tomcat8.5 版本 <Server port="800 ...

  4. 微信小程序跳H5页面

    主页面:index.wxml 主页面:index.js ↑跳转到另一个wxml页面→recharge.wxml recharge.wxml web-view中设置跳转h5的链接,可以加上需要的参数: ...

  5. sharePoint中简单的父页面跳转子页面代码!

    1,SharePoint中挺简单的一个父页面跳转到子页面的Js代码!常常用到,每次都到以前的项目中去找代码,挺麻烦! (1)父页面代码. function imgAddParentclick() { ...

  6. oracle database 9i/10g/11g 编程艺术 源代码下载

    背景 在找这本书的源码,搜到提供的都是需要C币下载的.比较固执(其实是穷). 在这本书的前言中提到源代码可以在 www.appress.com 上下载. 下面是该书在该网站上的链接: https:// ...

  7. lock free

    #include <thread> #include <iostream> #include <mutex> #include <atomic> #in ...

  8. Kafka 推荐网站

    Kafka系列文章 [Kafka设计解析(一)- Kafka背景及架构介绍](http://www.jasongj.com/2015/03/10/KafkaColumn1/) [Kafka设计解析(二 ...

  9. css 浮动说明

    clear:both; 1.要了解的:什么是浮动.浮在某面板之上. 例如:float:left; 向左停靠, 就是让需要设置浮动的元素,跟在指定元素后面. 先上实例: 比较常用导航: .nav_ul ...

  10. 学习新框架laravel4 第三天

    请求与输入 获取请求参数 如果没有传递默认值位1 $id= Input::get('id',1); //获取所有请求内容 Input::all() 取得请求 URI $uri = Request::p ...