349. Intersection of Two Arrays
来源:互联网 发布:音乐裁切软件 编辑:程序博客网 时间:2024/06/08 03:27
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
, return[2]
.
返回两个列表相同的元素 去重的
code:
class Solution(object):
def intersection(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
res=[]
if len(nums1)>=len(nums2):
nums3=sorted(nums1)
for y in nums2:
if y in nums3:
res.append(y)
else:
nums4=sorted(nums2)
for y in nums1:
if y in nums4:
nums4.remove(y)
res.append(y)
return list(set(res))
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays[][
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 349. Intersection of Two Arrays
- 【AtCoder073E】Ball Coloring
- shader数学基础之法线贴图切线空间
- maven构建ojdbc.jar包到本地仓库
- LINUX (一)命令基本格式和文件处理
- 邮件服务
- 349. Intersection of Two Arrays
- Codeforces 547C
- Qt快速入门第三版 3.3.1QFram类练习
- linux下的进程管理
- 蓝桥杯--第七届决赛:圆圈舞
- 参数间引用
- DIY电子相框
- pass by value & pass by reference
- GDOI2017 参赛总结