본문 바로가기

IT/코딩테스트

[Leetcode] 2956. Find Common Elements Between Two Arrays

728x90

https://leetcode.com/problems/find-common-elements-between-two-arrays

 

Find Common Elements Between Two Arrays - LeetCode

Can you solve this real interview question? Find Common Elements Between Two Arrays - You are given two 0-indexed integer arrays nums1 and nums2 of sizes n and m, respectively. Consider calculating the following values: * The number of indices i such that

leetcode.com

class Solution:
    def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:
        result = [0, 0]

        for i in range(0, len(nums1)):
            if nums1[i] in nums2:
                result[0] += 1

        for i in range(0, len(nums2)):
            if nums2[i] in nums1:
                result[1] += 1

        return result
728x90