题目
思路
哈希
代码
class Solution:
"""
@param: nums1: an integer array
@param: nums2: an integer array
@return: an integer array
"""
def intersection(self, nums1, nums2):
# write your code here
tmp_dict = {}
for num in nums1:
tmp_dict[num] = 1
res_list = []
for num in nums2:
if num in tmp_dict and tmp_dict[num]:
res_list.append(num)
tmp_dict[num] = 0
return res_list