题目
[1,2,2,1] ,[2,2] return [2,2]
思路
hash表
代码
def common_str(list1,list2):
hash1 = {}
for i in list1:
hash1[i] = 1 + hash1.get(i,0)
list = []
for j in list2:
if j in hash1 and hash1[j]>0:
list.append(j)
hash1[j] -= 1
return list
最后
以上就是酷炫身影最近收集整理的关于求两个数组公共集合的全部内容,更多相关求两个数组公共集合内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复