当前位置:网站首页>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
边栏推荐
- 全局平均池化层替代全连接层(最大池化和平均池化的区别)
- 线程池的使用二
- TensorRT安装及使用教程「建议收藏」
- 自制的数据库安全攻防题,相关靶机自己制作
- Batch大小不一定是2的n次幂!ML资深学者最新结论
- 使用CompletableFuture进行异步处理业务
- 技能大赛训练题:登录安全加固
- C#Assembly的使用
- Hard disk partition, expand disk C, no reshipment system, not heavy D dish of software full tutorial.
- Invalid bound statement (not found)出现的原因和解决方法
猜你喜欢
AI cocoa AI frontier introduction (7.31)
C#控件StatusStrip使用
The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
C# control StatusStrip use
[CPU Design Practice] Simple Pipeline CPU Design
IDEA找不到Database解决方法
49.【拷贝构造函数与重载】
C# Get network card information NetworkInterface IPInterfaceProperties
networkx绘制度分布
uniapp微信小程序引用标准版交易组件
随机推荐
numpy矩阵和向量的保存与加载,以及使用保存的向量进行相似度计算
Reasons and solutions for Invalid bound statement (not found)
抓住金三银四的尾巴,解锁程序员面试《刷题神器》
拥塞控制,CDN,端到端
Samba 远程命令执行漏洞(CVE-2017-7494)
C#控件CheckBox的使用
IDEA如何运行web程序
Introduction to using NPM
SAP 电商云 Spartacus SSR Optimization Engine 几处 timeout 的执行顺序
Six Stones Programming: No matter which function you think is useless, people who can use it will not be able to leave, so at least 99%
使用CompletableFuture进行异步处理业务
Batch大小不一定是2的n次幂!ML资深学者最新结论
ADS communicate with c #
基于神经网络的多柔性梁耦合结构振动控制
Shell脚本经典案例:探测批量主机是否存活
JSP中如何借助response对象实现页面跳转呢?
Usage of += in C#
页面整屏滚动效果
SAP e-commerce cloud Spartacus SSR Optimization Engine execution sequence of several timeouts
Sliding window method to segment data