当前位置:网站首页>leetcode:2032. 至少在两个数组中出现的值
leetcode:2032. 至少在两个数组中出现的值
2022-07-31 13:41:00 【心软且酷丶】
难度:简单
给你三个整数数组 nums1、nums2 和 nums3 ,请你构造并返回一个 元素各不相同的 数组,且由 至少 在 两个 数组中出现的所有值组成。数组中的元素可以按 任意 顺序排列。
示例 1:
输入:nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3] 输出:[3,2] 解释:至少在两个数组中出现的所有值为: - 3 ,在全部三个数组中都出现过。 - 2 ,在数组 nums1 和 nums2 中出现过。示例 2:
输入:nums1 = [3,1], nums2 = [2,3], nums3 = [1,2] 输出:[2,3,1] 解释:至少在两个数组中出现的所有值为: - 2 ,在数组 nums2 和 nums3 中出现过。 - 3 ,在数组 nums1 和 nums2 中出现过。 - 1 ,在数组 nums1 和 nums3 中出现过。示例 3:
输入:nums1 = [1,2,2], nums2 = [4,3,3], nums3 = [5] 输出:[] 解释:不存在至少在两个数组中出现的值。提示:
1 <= nums1.length, nums2.length, nums3.length <= 100
1 <= nums1[i], nums2[j], nums3[k] <= 100
题解:
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
边栏推荐
猜你喜欢
技能大赛训练题:登录安全加固
八大排序汇总及其稳定性
IDEA can't find the Database solution
PHP Serialization: eval
Error: npm ERR code EPERM
ECCV 2022 | Robotic Interaction Perception and Object Manipulation
How IDEA runs web programs
MATLAB | 我也做了一套绘图配色可视化模板
C#获得网卡信息 NetworkInterface IPInterfaceProperties
Spark学习:为Spark Sql添加自定义优化规则
随机推荐
龟速乘【模板】
Install the latest pytorch gpu version
Error IDEA Terminated with exit code 1
go使用makefile脚本编译应用
PHP序列化:eval
C# List用法 List介绍
抓住金三银四的尾巴,解锁程序员面试《刷题神器》
Text similarity calculation (Chinese and English) detailed explanation of actual combat
Network layer key protocol - IP protocol
mysql8, starttime的下一个值作为endtime的上一个值?
技能大赛训练题: 子网掩码划分案例
模拟量差分和单端(iou计算方法)
EXCEL如何快速拆分合并单元格数据
What should I do if selenium is reversed?
技能大赛训练题:登录安全加固
如何使用StarUML画类图[通俗易懂]
基于去噪自编码器的故障隔离与识别方法
C语言基础练(九九乘法表)与打印不同星号图案
Selenium自动化测试之Selenium IDE
[CPU Design Practice] Simple Pipeline CPU Design