当前位置:网站首页>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
边栏推荐
猜你喜欢
49.【拷贝构造函数与重载】
使用CompletableFuture进行异步处理业务
Reasons and solutions for Invalid bound statement (not found)
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
Install the latest pytorch gpu version
csdn发文助手问题
Solution for browser hijacking by hao360
动作捕捉系统用于柔性机械臂的末端定位控制
DELL SC compellent 康贝存储系统怎么抓取配置信息
对数字化时代的企业来说,数据治理难做,但应该去做
随机推荐
[RPI]树莓派监控温度及报警关机保护「建议收藏」
Reasons and solutions for Invalid bound statement (not found)
All-round visual monitoring of the Istio microservice governance grid (microservice architecture display, resource monitoring, traffic monitoring, link monitoring)
线程池的使用二
Golang - gin - pprof - use and safety
基于高阶微分器的无模型滑模控制器及其在自动电压调节器中的应用
Productivity Tools and Plugins
STM32的CAN过滤器
Istio微服务治理网格的全方面可视化监控(微服务架构展示、资源监控、流量监控、链路监控)
八大排序汇总及其稳定性
操作符详解
C#控件ListView用法
3.爬虫之Scrapy框架1安装与使用
Introduction to the PartImageNet Semantic Part Segmentation dataset
【牛客刷题-SQL大厂面试真题】NO3.电商场景(某东商城)
CodeIgniter 打开错误日志
Error: npm ERR code EPERM
0X7FFFFFFF,0X80000000「建议收藏」
Usage of += in C#
文本相似度计算(中英文)详解实战