题目如下:

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. C#打开文件

    C#中经常用到的功能,打开文件: /// <summary> /// 打开文件,可选择多个文件 /// </summary> /// <param name=" ...

  2. jmeter监控服务器性能(windows系统)

    一.jmeter安装插件 前两个是jmeter插件,安装到本地的jmeter文件夹下第三个是放到服务器里的 jmeter插件官网地址:https://jmeter-plugins.org/ [我分享的 ...

  3. navicat 系列软件一点击菜单栏就闪退

    现象:安装多个版本都出现了闪退的现象 解决方案:后来发现,原来是启动了有道词典屏幕取词才会出现这种现象,关了有道就没事.

  4. P2814 家谱

    我真没什么创意了woc.. so,为什么一道水题是蓝色的???哦哦哦,水好像就是蓝色的,emmm那就不是恶意评分了嘤嘤嘤 ... 好吧实际上可能是非c党对于字符串的处理需要进行编号和结构体,会麻烦一点 ...

  5. USACO3.3 A Game【区间dp】

    这道题也是一道非常有意思的区间$dp$,和在纪中的这道题有点像:取数游戏 (除了取数规则其它好像都一样诶) 当时在纪中的时候就觉得这个$dp$非常不好想,状态定义都不是很容易想到. 但是做过一道这种题 ...

  6. [转帖]达梦数据库(DM6)和ORACLE 10g的异同点

    达梦数据库(DM6)和ORACLE 10g的异同点    https://bbs.aliyun.com/detail/351337.html   花花浪子 级别: 小白 发帖 0 云币 -41 加关注 ...

  7. PhpStorm配置Xdebug调试

    安装xdebug 去官网下载对应版本的xdebug扩展 XDEBUG EXTENSION FOR PHP | DOWNLOADS 如何选择正确版本 输出phpinfo()函数的内容 查看输出页面的网页 ...

  8. 异步任务报错-Celery: WorkerLostError: Worker exited prematurely: signal 9 (SIGKILL)

    现象: 异步任务: 测试环境正常,线上环境报错 使用celery 进行后端异步任务时,报错: Celery: WorkerLostError: Worker exited prematurely: s ...

  9. 使用python的kazoo模块连接zookeeper实现最基本的增删改查

    kazoo的官方文档地址:https://kazoo.readthedocs.io/en/latest/index.html #!/usr/bin/env python # -*- coding: u ...

  10. CentOS 7 安装MongoDB 4.0

    1.创建yum源文件 /etc/yum.repos.d/mongodb-org-4.0.repo [mongodb-org-4.0] name=MongoDB Repository baseurl=h ...