aboutsummaryrefslogtreecommitdiff
path: root/find_common_element_2_arr.py
blob: f3a95b939930328367e95c2396c20a2c065a5f1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 2956. Find Common Elements Between Two Arrays

"""
given two integer arrays 'nums1' and 'nums2' of sizes 'n' and 'm'
respectively. calculate the following values: 'answer1' is the number of
indices 'i' such that 'nums1[i]' exists in 'nums2' and 'answer2' is the
number of indices 'i' such that 'nums2[i]' exist in 'nums1'
"""


class Solution(object):
    def findIntersectionValues(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        cnt1, cnt2 = 0, 0
        for i in nums1:
            if i in nums2:
                cnt1 += 1
        for i in nums2:
            if i in nums1:
                cnt2 += 1
        return cnt1, cnt2


if __name__ == "__main__":
    obj = Solution()
    print(obj.findIntersectionValues(nums1=[2, 3, 2], nums2=[1, 2]))
    print(obj.findIntersectionValues(nums1=[4, 3, 2, 3, 1], nums2=[2, 2, 5, 2, 3, 6]))
    print(obj.findIntersectionValues(nums1=[3, 4, 2, 3], nums2=[1, 5]))