题目如下:

Given three integer arrays arr1arr2 and arr3 sorted in strictly increasing order, return a sorted array of only the integers that appeared in all three arrays.

Example 1:

Input: arr1 = [1,2,3,4,5], arr2 = [1,2,5,7,9], arr3 = [1,3,4,5,8]
Output: [1,5]
Explanation: Only 1 and 5 appeared in the three arrays.

Constraints:

  • 1 <= arr1.length, arr2.length, arr3.length <= 1000
  • 1 <= arr1[i], arr2[i], arr3[i] <= 2000

解题思路:【leetcode&CN&竞赛】1198.Find Smallest Common Element in All Rows 类似,但是本题约定了每个数组中的元素是唯一的,所以只需要遍历三个数组,计算出每个元素出现的次数即可。

代码如下:

class Solution(object):
def arraysIntersection(self, arr1, arr2, arr3):
"""
:type arr1: List[int]
:type arr2: List[int]
:type arr3: List[int]
:rtype: List[int]
"""
val = [0] * 2001
for i in arr1:
val[i] += 1
for i in arr2:
val[i] += 1
for i in arr3:
val[i] += 1
res = []
for i,v in enumerate(val):
if v == 3:res.append(i)
return res

【leetcode】1213.Intersection of Three Sorted Arrays的更多相关文章

  1. 【LeetCode】4. Median of Two Sorted Arrays(思维)

    [题意] 给两个有序数组,寻找两个数组组成后的中位数,要求时间复杂度为O(log(n+m)). [题解] 感觉这道题想法非常妙!! 假定原数组为a,b,数组长度为lena,lenb. 那么中位数一定是 ...

  2. 【LeetCode】4. Median of Two Sorted Arrays 寻找两个正序数组的中位数

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:数组,中位数,题解,leetcode, 力扣,python ...

  3. 【leetcode】4. Median of Two Sorted Arrays

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

  4. 【LeetCode】4. Median of Two Sorted Arrays (2 solutions)

    Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. Find t ...

  5. 【LeetCode】004. Median of Two Sorted Arrays

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

  6. 【LeetCode】4.Median of Two Sorted Arrays 两个有序数组中位数

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

  7. 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告

    今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sort ...

  8. 【一天一道LeetCode】#4 Median of Two Sorted Arrays

    一天一道LeetCode (一)题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find th ...

  9. 【LeetCode】33. Search in Rotated Sorted Array (4 solutions)

    Search in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you before ...

随机推荐

  1. goland搭建beego开发环境

    1.安装最新的go软件 ,当前版本1.122.下载goland开发工具3.安装bee工具 go get github.com/beego/bee4.通过bee api dsh -tables=&quo ...

  2. 【HANA系列】SAP HANA计算视图中的RANK使用方法

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA计算视图中的RA ...

  3. mysql——多表——外连接查询——左连接、右连接、复合条件查询

    ), d_id ), name ), age ), sex ), homeadd ) ); ,,,'nan','beijing'); ,,,'nv','hunan'); ,,,'nan','jiang ...

  4. CDH管理节点扩容磁盘步骤

    把4个节点加12G内存,把hive的heap调到6G,按group重启服务让配置生效 注: 停服务前在yarn的application webui查flink的application id yarn ...

  5. neo4j3.0多数库切换

    动机 类似与关系型数据库,创建了多个数据库 想要像访问关系型数据库那样来可以无缝切换多个数据库 然而,在neo4j 3.0都暂时没有办法做到:每次启动neo4j,它只能读取一个数据库.比如,现在有两个 ...

  6. Springg MVC 中文乱码处理

    1.对于post请求的处理方式,在web.xml添加拦截器 <filter> <filter-name>CharacterEncodingFilter</filter-n ...

  7. 7大python 深度学习框架的描述及优缺点绍

    Theano https://github.com/Theano/Theano 描述: Theano 是一个python库, 允许你定义, 优化并且有效地评估涉及到多维数组的数学表达式. 它与GPUs ...

  8. 2019 Multi-University Training Contest 8 - 1006 - Acesrc and Travel - 树形dp

    http://acm.hdu.edu.cn/showproblem.php?pid=6662 仿照 CC B - TREE 那道题的思路写的,差不多.也是要走路径. 像这两种必须走到叶子的路径感觉是必 ...

  9. C++ 调用C语言、extern "C"、__cplusplus关键字

    ——C++编译器完全兼容C语言的编译方式.(但是得有源代码) ——C++编译器会优先使用C++的编译方式进行编译 ——extern "C" 关键字能够强制C++编译器进行C方式的编 ...

  10. PropertyUtilsBean 将bean转成map

    public static Map<String,String> beanToMap(Object bean) { Map<String,String> params =Map ...