<!--|This file generated by command(leetcode description); DO NOT EDIT.    |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author    openset <<EMAIL>>                           |-->
<!--|@link      https://github.com/openset                                 |-->
<!--|@home      https://github.com/tonymontaro/leetcode-hints                        |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/tonymontaro/leetcode-hints/tree/master/problems/intersection-of-two-arrays "Intersection of Two Arrays")
　　　　　　　　　　　　　　　　
[Next >](https://github.com/tonymontaro/leetcode-hints/tree/master/problems/android-unlock-patterns "Android Unlock Patterns")

## [350. Intersection of Two Arrays II (Easy)](https://leetcode.com/problems/intersection-of-two-arrays-ii "两个数组的交集 II")

<p>Given two arrays, write a function to compute their intersection.</p>

<p><strong>Example 1:</strong></p>

<pre>
<strong>Input: </strong>nums1 = <span id="example-input-1-1">[1,2,2,1]</span>, nums2 = <span id="example-input-1-2">[2,2]</span>
<strong>Output: </strong><span id="example-output-1">[2,2]</span>
</pre>

<div>
<p><strong>Example 2:</strong></p>

<pre>
<strong>Input: </strong>nums1 = <span id="example-input-2-1">[4,9,5]</span>, nums2 = <span id="example-input-2-2">[9,4,9,8,4]</span>
<strong>Output: </strong><span id="example-output-2">[4,9]</span></pre>
</div>

<p><b>Note:</b></p>

<ul>
	<li>Each element in the result should appear as many times as it shows in both arrays.</li>
	<li>The result can be in any order.</li>
</ul>

<p><b>Follow up:</b></p>

<ul>
	<li>What if the given array is already sorted? How would you optimize your algorithm?</li>
	<li>What if <i>nums1</i>&#39;s size is small compared to <i>nums2</i>&#39;s size? Which algorithm is better?</li>
	<li>What if elements of <i>nums2</i> are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?</li>
</ul>

### Related Topics
  [[Sort](https://github.com/tonymontaro/leetcode-hints/tree/master/tag/sort/README.md)]
  [[Hash Table](https://github.com/tonymontaro/leetcode-hints/tree/master/tag/hash-table/README.md)]
  [[Two Pointers](https://github.com/tonymontaro/leetcode-hints/tree/master/tag/two-pointers/README.md)]
  [[Binary Search](https://github.com/tonymontaro/leetcode-hints/tree/master/tag/binary-search/README.md)]

### Similar Questions
  1. [Intersection of Two Arrays](https://github.com/tonymontaro/leetcode-hints/tree/master/problems/intersection-of-two-arrays) (Easy)
  1. [Find Common Characters](https://github.com/tonymontaro/leetcode-hints/tree/master/problems/find-common-characters) (Easy)
