Skip to main content

20240716 2956 - Easy - Array

2956. Find Common Elements Between Two Arrays

class Solution:
def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:
nd = dict()
nd2 = dict()
ans1 = 0
ans2 = 0
for n in nums1:
if n not in nd:
nd[n] = True
for n in nums2:
if n in nd:
ans2 += 1
if n not in nd2:
nd2[n] = True
for n in nums1:
if n in nd2:
ans1 += 1
return [ans1, ans2]