# 解题思路:字典 20190302 找工作期间
class Solution(object):
def intersect(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
dic = dict()
res = []
for i in range(len(nums1)):
if nums1[i] not in dic:
dic[nums1[i]] = 1
else:
dic[nums1[i]] += 1
for j in range(len(nums2)):
if nums2[j] in dic:
if dic[nums2[j]] > 0 :
res.append(nums2[j])
dic[nums2[j]] -= 1
return res
s = Solution()
n1 = [4,9,5]
n2 = [9,4,9,8,4]
print s.intersect(n1,n2)