Problem statement

https://leetcode.com/problems/intersection-of-two-arrays/

Solution

Put number into set and evaluate intersection of two sets.

Complexity

It is O(m + n) for time and space.

Code

class Solution:
    def intersection(self, nums1, nums2):
        return set(nums1) & set(nums2)

Remark

We can also sort our sets and use two pointers approach with overall O(n log n + m log m) complexity.