mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of sizes <code>n</code> and <code>m</code>, respectively.</p>
 | 
						|
 | 
						|
<p>Consider calculating the following values:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>The number of indices <code>i</code> such that <code>0 <= i < n</code> and <code>nums1[i]</code> occurs <strong>at least</strong> once in <code>nums2</code>.</li>
 | 
						|
	<li>The number of indices <code>i</code> such that <code>0 <= i < m</code> and <code>nums2[i]</code> occurs <strong>at least</strong> once in <code>nums1</code>.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>Return <em>an integer array </em><code>answer</code><em> of size </em><code>2</code><em> containing the two values <strong>in the above order</strong></em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
 | 
						|
<strong>Output:</strong> [3,4]
 | 
						|
<strong>Explanation:</strong> We calculate the values as follows:
 | 
						|
- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3.
 | 
						|
- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> nums1 = [3,4,2,3], nums2 = [1,5]
 | 
						|
<strong>Output:</strong> [0,0]
 | 
						|
<strong>Explanation:</strong> There are no common elements between the two arrays, so the two values will be 0.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>n == nums1.length</code></li>
 | 
						|
	<li><code>m == nums2.length</code></li>
 | 
						|
	<li><code>1 <= n, m <= 100</code></li>
 | 
						|
	<li><code>1 <= nums1[i], nums2[i] <= 100</code></li>
 | 
						|
</ul>
 |