mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										34
									
								
								算法题(国外版)/intersection-of-two-arrays-ii.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								算法题(国外版)/intersection-of-two-arrays-ii.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
<p>Given two integer arrays <code>nums1</code> and <code>nums2</code>, return <em>an array of their intersection</em>. Each element in the result must appear as many times as it shows in both arrays and you may return the result in <strong>any order</strong>.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> nums1 = [1,2,2,1], nums2 = [2,2]
 | 
			
		||||
<strong>Output:</strong> [2,2]
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> nums1 = [4,9,5], nums2 = [9,4,9,8,4]
 | 
			
		||||
<strong>Output:</strong> [4,9]
 | 
			
		||||
<strong>Explanation:</strong> [9,4] is also accepted.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Constraints:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li><code>1 <= nums1.length, nums2.length <= 1000</code></li>
 | 
			
		||||
	<li><code>0 <= nums1[i], nums2[i] <= 1000</code></li>
 | 
			
		||||
</ul>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Follow up:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li>What if the given array is already sorted? How would you optimize your algorithm?</li>
 | 
			
		||||
	<li>What if <code>nums1</code>'s size is small compared to <code>nums2</code>'s size? Which algorithm is better?</li>
 | 
			
		||||
	<li>What if elements of <code>nums2</code> are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?</li>
 | 
			
		||||
</ul>
 | 
			
		||||
		Reference in New Issue
	
	Block a user