본문 바로가기
python-algorithm

leetcode 2956. Find Common Elements Between Two Arrays

by 무적김두칠 2023. 12. 27.

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

 

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

 

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]:
        answer = [00]
        for num in nums1:
            if num in nums2:
                answer[0+= 1
        for num in nums2:
            if num in nums1:
                answer[1+= 1
        
        return answer
cs
반응형

댓글