mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你两个整数数组 <code>arr1</code> , <code>arr2</code> 和一个整数 <code>d</code> ,请你返回两个数组之间的 <strong>距离值</strong> 。</p>
 | 
						||
 | 
						||
<p>「<strong>距离值</strong>」<strong> </strong>定义为符合此距离要求的元素数目:对于元素 <code>arr1[i]</code> ,不存在任何元素 <code>arr2[j]</code> 满足 <code>|arr1[i]-arr2[j]| <= d</code> 。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>
 | 
						||
对于 arr1[0]=4 我们有:
 | 
						||
|4-10|=6 > d=2 
 | 
						||
|4-9|=5 > d=2 
 | 
						||
|4-1|=3 > d=2 
 | 
						||
|4-8|=4 > d=2 
 | 
						||
所以 arr1[0]=4 符合距离要求
 | 
						||
 | 
						||
对于 arr1[1]=5 我们有:
 | 
						||
|5-10|=5 > d=2 
 | 
						||
|5-9|=4 > d=2 
 | 
						||
|5-1|=4 > d=2 
 | 
						||
|5-8|=3 > d=2
 | 
						||
所以 arr1[1]=5 也符合距离要求
 | 
						||
 | 
						||
对于 arr1[2]=8 我们有:
 | 
						||
<strong>|8-10|=2 <= d=2</strong>
 | 
						||
<strong>|8-9|=1 <= d=2</strong>
 | 
						||
|8-1|=7 > d=2
 | 
						||
<strong>|8-8|=0 <= d=2</strong>
 | 
						||
存在距离小于等于 2 的情况,不符合距离要求 
 | 
						||
 | 
						||
故而只有 arr1[0]=4 和 arr1[1]=5 两个符合距离要求,距离值为 2</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3
 | 
						||
<strong>输出:</strong>2
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6
 | 
						||
<strong>输出:</strong>1
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= arr1.length, arr2.length <= 500</code></li>
 | 
						||
	<li><code>-10^3 <= arr1[i], arr2[j] <= 10^3</code></li>
 | 
						||
	<li><code>0 <= d <= 100</code></li>
 | 
						||
</ul>
 |