mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加0349.两个数组的交集 python3版本
This commit is contained in:
@ -118,6 +118,17 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python3
|
||||||
|
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 result_set
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
Reference in New Issue
Block a user