文章作者:Tyan 博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Version 1
class Solution:
def intersection(self, nums1, nums2):
result = set()
for x in nums1:
if x in nums2:
result.add(x)
return list(result)
- Version 2
class Solution:
def intersection(self, nums1, nums2):
result = set()
stat = {}
for x in nums1:
stat[x] = x
for x in nums2:
if x in stat:
result.add(x)
return list(result)
- Version 3
class Solution:
def intersection(self, nums1, nums2):
return list(set(nums1) & set(nums2))
Reference
- https://leetcode.com/problems/intersection-of-two-arrays/