【leetcode】1213.Intersection of Three Sorted Arrays
题目如下:
Given three integer arrays
arr1,arr2andarr3sorted 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 <= 10001 <= 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的更多相关文章
- 【LeetCode】4. Median of Two Sorted Arrays(思维)
[题意] 给两个有序数组,寻找两个数组组成后的中位数,要求时间复杂度为O(log(n+m)). [题解] 感觉这道题想法非常妙!! 假定原数组为a,b,数组长度为lena,lenb. 那么中位数一定是 ...
- 【LeetCode】4. Median of Two Sorted Arrays 寻找两个正序数组的中位数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:数组,中位数,题解,leetcode, 力扣,python ...
- 【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 ...
- 【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 ...
- 【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 ...
- 【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 ...
- 【LeetCode】Find Minimum in Rotated Sorted Array 解题报告
今天看到LeetCode OJ题目下方多了"Show Tags"功能.我觉着挺好,方便刚開始学习的人分类练习.同一时候也是解题时的思路提示. [题目] Suppose a sort ...
- 【一天一道LeetCode】#4 Median of Two Sorted Arrays
一天一道LeetCode (一)题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find th ...
- 【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 ...
随机推荐
- 使用Jquery的Ajax调用
最近在学习web开发,试用了一下Jquery的ajax调用. 首先,新建一个MVC4的项目,在HomeController.cs中添加一个Action,命名为GetData, 通过这个为ajax提供数 ...
- js中的break,continue和return的用法及区别
为什么要说个?好像很简单,但是我也会迷糊,不懂有时候为什么要用return,然而break和continue也经常和他放在一起. 所以就一起来说一说,这三个看起来很简单,却常常会出错的关键词的具体用法 ...
- 转·带你用实例理解C语言回调函数
原文出处:https://segmentfault.com/a/1190000008293902?utm_source=tag-newest 前言: 如不懂函数指针,请先查阅关于函数指针内容的资料(h ...
- (转)GIS中的4D产品(DLG、DRG、DEM、DOM)
DLG 数字线划地图(DLG, Digital Line Graphic):是与现有线划基本一致的各地图要素的矢量 数据集,且保存各要素间的空间关系和相关的属性信息. 在世字测图中,最为常见的产品就是 ...
- html+css实现奥运五环(环环相扣)
<!DOCTYPE html> <html> <head> <title>奥运五环</title> <style type=" ...
- 通过node指令自动创建一个package.json文件,并封装发布使用
通过node指令自动创建一个package.json文件,并封装发布使用:https://blog.csdn.net/scu_cindy/article/details/78208268
- Tomcat使用时出现的问题总结
1.有两种办法解决Tomcat启动时端口号冲突问题 1.第一种: 查看本地端口使用情况,找到被占用的8080端口,杀死该进程 1.查看本地端口命令:cmd->netstat -ano 2.找到 ...
- Python 把较长的一行代码分成多行的技巧
概述:在写代码过程中,经常遇到一行代码很长的情况.为了让代码显得整齐干净,就需要把一行代码分成多行来写,Python中有三种小技巧可以实现该功能: 1.用反斜杠\链接多行代码 示例: ...
- CSP-S全国模拟赛第三场 【nan死了】
mmt 居然第一步膜化乘除 都没看出来,没救了... 大概是贡献前缀和优化的做法 巨兔式讲解:大家都学会了么? 咱发现有大量的 (i/j , i%j ) 同时 对很多 c 产生了贡献,咱可以去优化这一 ...
- [.net core]9.中间件的具体实现
查看Startup.cs的configure方法 public void Configure(IApplicationBuilder app, IHostingEnvironment env) { i ...