mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 07:51:41 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个下标从 <strong>0</strong> 开始、由 <code>n</code> 个整数组成的数组 <code>arr</code> 。</p>\n\n<p><code>arr</code> 中两个元素的 <strong>间隔</strong> 定义为它们下标之间的 <strong>绝对差</strong> 。更正式地,<code>arr[i]</code> 和 <code>arr[j]</code> 之间的间隔是 <code>|i - j|</code> 。</p>\n\n<p>返回一个长度为 <code>n</code> 的数组 <code>intervals</code> ,其中 <code>intervals[i]</code> 是<em> </em><code>arr[i]</code><em> </em>和<em> </em><code>arr</code><em> </em>中每个相同元素(与 <code>arr[i]</code> 的值相同)的 <strong>间隔之和</strong> <em>。</em></p>\n\n<p><strong>注意:</strong><code>|x|</code> 是 <code>x</code> 的绝对值。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>arr = [2,1,3,1,2,3,3]\n<strong>输出:</strong>[4,2,7,2,4,4,5]\n<strong>解释:</strong>\n- 下标 0 :另一个 2 在下标 4 ,|0 - 4| = 4\n- 下标 1 :另一个 1 在下标 3 ,|1 - 3| = 2\n- 下标 2 :另两个 3 在下标 5 和 6 ,|2 - 5| + |2 - 6| = 7\n- 下标 3 :另一个 1 在下标 1 ,|3 - 1| = 2\n- 下标 4 :另一个 2 在下标 0 ,|4 - 0| = 4\n- 下标 5 :另两个 3 在下标 2 和 6 ,|5 - 2| + |5 - 6| = 4\n- 下标 6 :另两个 3 在下标 2 和 5 ,|6 - 2| + |6 - 5| = 5\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>arr = [10,5,10,10]\n<strong>输出:</strong>[5,0,3,4]\n<strong>解释:</strong>\n- 下标 0 :另两个 10 在下标 2 和 3 ,|0 - 2| + |0 - 3| = 5\n- 下标 1 :只有这一个 5 在数组中,所以到相同元素的间隔之和是 0\n- 下标 2 :另两个 10 在下标 0 和 3 ,|2 - 0| + |2 - 3| = 3\n- 下标 3 :另两个 10 在下标 0 和 2 ,|3 - 0| + |3 - 2| = 4\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == arr.length</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= arr[i] <= 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 32,
|
||||
"likes": 36,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -149,7 +149,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"4.8K\", \"totalSubmission\": \"13.6K\", \"totalAcceptedRaw\": 4845, \"totalSubmissionRaw\": 13591, \"acRate\": \"35.6%\"}",
|
||||
"stats": "{\"totalAccepted\": \"5.1K\", \"totalSubmission\": \"14.1K\", \"totalAcceptedRaw\": 5123, \"totalSubmissionRaw\": 14071, \"acRate\": \"36.4%\"}",
|
||||
"hints": [
|
||||
"For each unique value found in the array, store a sorted list of indices of elements that have this value in the array.",
|
||||
"One way of doing this is to use a HashMap that maps the values to their list of indices. Update this mapping as you iterate through the array.",
|
||||
|
Reference in New Issue
Block a user