更新 0349.两个数组的交集.md python代码简化

一行代码解决
This commit is contained in:
Eyjan_Huang
2021-08-16 15:42:28 +08:00
committed by GitHub
parent 1aab307ed7
commit d350a4dd82

View File

@ -121,13 +121,7 @@ Python
```python
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
result_set = set()
set1 = set(nums1)
for num in nums2:
if num in set1:
result_set.add(num) # set1里出现的nums2元素 存放到结果
return list(result_set)
return list(set(nums1) & set(nums2)) # 两个数组线变成集合,求交集后还原为数组
```