mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Create intersection_two_arrays.py
This commit is contained in:
parent
f2418e56c1
commit
23881f329f
11
arrays_and_strings/intersection_two_arrays.py
Normal file
11
arrays_and_strings/intersection_two_arrays.py
Normal file
@ -0,0 +1,11 @@
|
||||
def intersect(nums1: list[int], nums2: list[int]) -> list[int]:
|
||||
|
||||
result = []
|
||||
set_nums = set(nums1) & set(nums2)
|
||||
counter = Counter(nums1) & Counter(nums2)
|
||||
|
||||
for n in set_nums:
|
||||
result.extend([n]*counter[n])
|
||||
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user