当前位置:网站首页>leetcode:2032. Values that appear in at least two arrays
leetcode:2032. Values that appear in at least two arrays
2022-07-31 13:46:00 【Soft-hearted and cool】
Difficulty: Easy
Give you three integer arrays nums1, nums2 and nums3, please construct and return an array with different elements, and by at least two arrays appearing in the arrayall values.Elements in an array can be in any order.
Example 1:
Input:nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]Output:[3,2]Explanation: All values that appear in at least two arrays are:- 3 , which occurs in all three arrays.- 2 , which appeared in the arrays nums1 and nums2.Example 2:
Input:nums1 = [3,1], nums2 = [2,3], nums3 = [1,2]Output:[2,3,1]Explanation: All values that appear in at least two arrays are:- 2 , which appeared in the arrays nums2 and nums3 .- 3 , which appeared in the arrays nums1 and nums2.- 1 , which appeared in arrays nums1 and nums3.Example 3:
Input:nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5]Output:[]Explanation: There is no value that appears in at least two arrays.Tip:
1 <= nums1.length, nums2.length, nums3.length <= 100
1 <= nums1[i], nums2[j], nums3[k] <= 100
Solution:
class Solution:def twoOutOfThree(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:_list = []res = []for i in nums1:_list.append(i)for j in nums2:_list.append(j)for k in nums3:_list.append(k)a = set(_list)a = list(a)for s in a:if (s in nums1 and s in nums2 ) or (s in nums1 and s in nums3) or (s in nums2 and s in nums3) or (s in nums1 and s in nums2 and s in nums3):res.append(s)set(res)list(res)return res
边栏推荐
- Install the latest pytorch gpu version
- Unity study notes Description of AVPro video jump function (Seeking)
- [Niu Ke brush questions - SQL big factory interview questions] NO3. E-commerce scene (some east mall)
- 全局平均池化层替代全连接层(最大池化和平均池化的区别)
- C#高级--委托
- 【蓝桥杯选拔赛真题46】Scratch磁铁游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
- golang-gin - graceful restart
- 3.爬虫之Scrapy框架1安装与使用
- JSP中如何借助response对象实现页面跳转呢?
- 技能大赛训练题:登录安全加固
猜你喜欢
八大排序汇总及其稳定性
Install the latest pytorch gpu version
IDEA can't find the Database solution
endnote引用
An article makes it clear!What is the difference and connection between database and data warehouse?
ADS与C#通信
SetoolKit使用指南
Reasons and solutions for Invalid bound statement (not found)
一篇文章讲清楚!数据库和数据仓库到底有什么区别和联系?
3.爬虫之Scrapy框架1安装与使用
随机推荐
AI cocoa AI frontier introduction (7.31)
抓住金三银四的尾巴,解锁程序员面试《刷题神器》
Sliding window method to segment data
IDEA如何运行web程序
Install the latest pytorch gpu version
Unity学习笔记 关于AVPro视频跳转功能(Seeking)的说明
C#Assembly的使用
模拟量差分和单端(iou计算方法)
The operator,
SetoolKit使用指南
uniapp微信小程序引用标准版交易组件
如何使用StarUML画类图[通俗易懂]
技能大赛训练题:MS15_034漏洞验证与安全加固
最新完整代码:使用word2vec预训练模型进行增量训练(两种保存方式对应的两种加载方式)适用gensim各种版本
C# Get network card information NetworkInterface IPInterfaceProperties
pytorch gpu版本安装最新
4.爬虫之Scrapy框架2数据解析&配置参数&数据持久化&提高Scrapy效率
MySQL玩到这种程度,难怪大厂抢着要!
golang-gin - graceful restart
六石编程学:不论是哪个功能,你觉得再没用,会用的人都离不了,所以至少要做到99%