Intersection of Two Arrays II

Intersection of Two Arrays II

Given two arrays, write a function to compute their intersection.

Example

Input: nums1 = [1,2,2,1], nums2 = [2,2]
Output: [2,2]

Solution

class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        return list((collections.Counter(nums1) & collections.Counter(nums2)).elements())

你可能感兴趣的:(leetcode,trick)