Skip to content

Commit 3591597

Browse files
authored
Create intersectionTwoArrays_II.py
1 parent d57e81d commit 3591597

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def intersect(self, nums1, nums2):
3+
"""
4+
:type nums1: List[int]
5+
:type nums2: List[int]
6+
:rtype: List[int]
7+
"""
8+
if not nums1 or not nums2:
9+
return []
10+
d1={}
11+
res=[]
12+
13+
for n in nums1:
14+
d1[n] =1 if n not in d1 else d1[n] +1
15+
16+
for m in nums2:
17+
if d1.get(m)>0:
18+
res.append(m)
19+
d1[m] -=1
20+
21+
return res

0 commit comments

Comments
 (0)