day06 代码随想录算法训练营 349. 两个数组的交集
题目:349. 两个数组的交集
我的感悟:
- 轻轻松松
理解难点:
- python中 字典存,集合去重
代码难点:
- del要掌握
- dic.get(i,0) +1 要掌握
总结概括:
- 无
代码示例:
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
# 用字典dic存+集合set去重
dic = {}
for i in nums1:
dic[i] = dic.get(i,0) + 1
res = set()
for i in nums2:
if i in dic:
res.add(i)
del dic[i]
return list(res)
通过截图:
资料:
题目链接/文章讲解/视频讲解:https://programmercarl.com/0349.%E4%B8%A4%E4%B8%AA%E6%95%B0%E7%BB%84%E7%9A%84%E4%BA%A4%E9%9B%86.html