Leetcode 350 - Intersection of two arrays II

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

Example 2:

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.