mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-02 14:12:17 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个整数数组 <code>nums</code> ,请计算数组的 <strong>中心下标 </strong>。</p>\n\n<p>数组<strong> 中心下标</strong><strong> </strong>是数组的一个下标,其左侧所有元素相加的和等于右侧所有元素相加的和。</p>\n\n<p>如果中心下标位于数组最左端,那么左侧数之和视为 <code>0</code> ,因为在下标的左侧不存在元素。这一点对于中心下标位于数组最右端同样适用。</p>\n\n<p>如果数组有多个中心下标,应该返回 <strong>最靠近左边</strong> 的那一个。如果数组不存在中心下标,返回 <code>-1</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1, 7, 3, 6, 5, 6]\n<strong>输出:</strong>3\n<strong>解释:</strong>\n中心下标是 3 。\n左侧数之和 sum = nums[0] + nums[1] + nums[2] = 1 + 7 + 3 = 11 ,\n右侧数之和 sum = nums[4] + nums[5] = 5 + 6 = 11 ,二者相等。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1, 2, 3]\n<strong>输出:</strong>-1\n<strong>解释:</strong>\n数组中不存在满足此条件的中心下标。</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [2, 1, -1]\n<strong>输出:</strong>0\n<strong>解释:</strong>\n中心下标是 0 。\n左侧数之和 sum = 0 ,(下标 0 左侧不存在元素),\n右侧数之和 sum = nums[1] + nums[2] = 1 + -1 = 0 。</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>\n\t<li><code>-1000 <= nums[i] <= 1000</code></li>\n</ul>\n\n<p> </p>\n\n<p><strong>注意:</strong>本题与主站 1991 题相同:<a href=\"https://leetcode-cn.com/problems/find-the-middle-index-in-array/\" target=\"_blank\">https://leetcode-cn.com/problems/find-the-middle-index-in-array/</a></p>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 381,
|
||||
"likes": 391,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Subarray Sum Equals K\", \"titleSlug\": \"subarray-sum-equals-k\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u548c\\u4e3a K \\u7684\\u5b50\\u6570\\u7ec4\"}]",
|
||||
@@ -143,7 +143,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"170.2K\", \"totalSubmission\": \"353.2K\", \"totalAcceptedRaw\": 170153, \"totalSubmissionRaw\": 353164, \"acRate\": \"48.2%\"}",
|
||||
"stats": "{\"totalAccepted\": \"176.5K\", \"totalSubmission\": \"364.4K\", \"totalAcceptedRaw\": 176545, \"totalSubmissionRaw\": 364449, \"acRate\": \"48.4%\"}",
|
||||
"hints": [
|
||||
"We can precompute prefix sums P[i] = nums[0] + nums[1] + ... + nums[i-1].\r\nThen for each index, the left sum is P[i], and the right sum is P[P.length - 1] - P[i] - nums[i]."
|
||||
],
|
||||
|
Reference in New Issue
Block a user