# Leetcode 350 - Intersection of two arrays II

Given two arrays, write a function to compute their intersection.**Example 1:**

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

**Example 2:**

1 | Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] |

**Note:**

- Each element in the result should appear as many times as it shows in both arrays.
- The result can be in any order.

`Thoughts`

: Took a bit longer to understand what the question means by ‘as many times’. Use `Map()`

is the way. First, to build a map and record occurrences of each unique elements, then iterate over `nums2`

and add elements to `res`

if the value of element in Map is no less than `1`

.

1 | /** |