Skip to content

Commit 8d5447c

Browse files
committed
Time: 52 ms (80.90%), Space: 14.2 MB (55.46%) - LeetHub
1 parent f68c82d commit 8d5447c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
3+
n1 = collections.Counter(nums1)
4+
n2 = {}
5+
6+
for num in nums2:
7+
if num in n1:
8+
if num not in n2:
9+
n2[num] = 0
10+
n2[num] += 1
11+
res = []
12+
for num,freq in n2.items():
13+
f = 0
14+
if num in n1:
15+
f = min(freq,n1[num])
16+
17+
for _ in range(f):
18+
res.append(num)
19+
20+
return res

0 commit comments

Comments
 (0)