mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-26 07:18:56 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你两个整数数组 <code>arr1</code> , <code>arr2</code> 和一个整数 <code>d</code> ,请你返回两个数组之间的 <strong>距离值</strong> 。</p>\n\n<p>「<strong>距离值</strong>」<strong> </strong>定义为符合此距离要求的元素数目:对于元素 <code>arr1[i]</code> ,不存在任何元素 <code>arr2[j]</code> 满足 <code>|arr1[i]-arr2[j]| <= d</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2\n<strong>输出:</strong>2\n<strong>解释:</strong>\n对于 arr1[0]=4 我们有:\n|4-10|=6 > d=2 \n|4-9|=5 > d=2 \n|4-1|=3 > d=2 \n|4-8|=4 > d=2 \n所以 arr1[0]=4 符合距离要求\n\n对于 arr1[1]=5 我们有:\n|5-10|=5 > d=2 \n|5-9|=4 > d=2 \n|5-1|=4 > d=2 \n|5-8|=3 > d=2\n所以 arr1[1]=5 也符合距离要求\n\n对于 arr1[2]=8 我们有:\n<strong>|8-10|=2 <= d=2</strong>\n<strong>|8-9|=1 <= d=2</strong>\n|8-1|=7 > d=2\n<strong>|8-8|=0 <= d=2</strong>\n存在距离小于等于 2 的情况,不符合距离要求 \n\n故而只有 arr1[0]=4 和 arr1[1]=5 两个符合距离要求,距离值为 2</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3\n<strong>输出:</strong>2\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6\n<strong>输出:</strong>1\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr1.length, arr2.length <= 500</code></li>\n\t<li><code>-10^3 <= arr1[i], arr2[j] <= 10^3</code></li>\n\t<li><code>0 <= d <= 100</code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 32,
|
||||
"likes": 46,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"16.6K\", \"totalSubmission\": \"23.9K\", \"totalAcceptedRaw\": 16607, \"totalSubmissionRaw\": 23855, \"acRate\": \"69.6%\"}",
|
||||
"stats": "{\"totalAccepted\": \"20.1K\", \"totalSubmission\": \"29.8K\", \"totalAcceptedRaw\": 20132, \"totalSubmissionRaw\": 29833, \"acRate\": \"67.5%\"}",
|
||||
"hints": [
|
||||
"Sort 'arr2' and use binary search to get the closest element for each 'arr1[i]', it gives a time complexity of O(nlogn)."
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user