---
description: '# Easy'
---

# 349. Intersection of Two Arrays

{% hint style="info" %}
Key: use set to improve efficiency.
{% endhint %}

{% tabs %}
{% tab title="Python" %}
```python
class Solution:
    def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
        result = set()
        set1 = set(nums1)
        set2 = set(nums2)
        
        if len(set1)  <  len(set2):
            return self.helper(set1, set2)
        else:
            return self.helper(set2, set1)
        
    def helper(self, set1, set2):
        return [x for x in set1 if x in set2]

```

Time complexity = $$O(m+n)$$ . Space complexity = $$O(n+m)$$ except the result.
{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}

