mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-21 21:16:45 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给你一个整数数组 <code>nums</code> 。你需要选择 <strong>恰好</strong> 一个下标(下标从 <strong>0</strong> 开始)并删除对应的元素。请注意剩下元素的下标可能会因为删除操作而发生改变。</p>\n\n<p>比方说,如果 <code>nums = [6,1,7,4,1]</code> ,那么:</p>\n\n<ul>\n\t<li>选择删除下标 <code>1</code> ,剩下的数组为 <code>nums = [6,7,4,1]</code> 。</li>\n\t<li>选择删除下标 <code>2</code> ,剩下的数组为 <code>nums = [6,1,4,1]</code> 。</li>\n\t<li>选择删除下标 <code>4</code> ,剩下的数组为 <code>nums = [6,1,7,4]</code> 。</li>\n</ul>\n\n<p>如果一个数组满足奇数下标元素的和与偶数下标元素的和相等,该数组就是一个 <strong>平衡数组</strong> 。</p>\n\n<p>请你返回删除操作后,剩下的数组<em> </em><code>nums</code><em> </em>是 <strong>平衡数组</strong> 的 <strong>方案数</strong> 。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [2,1,6,4]\n<b>输出:</b>1\n<strong>解释:</strong>\n删除下标 0 :[1,6,4] -> 偶数元素下标为:1 + 4 = 5 。奇数元素下标为:6 。不平衡。\n删除下标 1 :[2,6,4] -> 偶数元素下标为:2 + 4 = 6 。奇数元素下标为:6 。平衡。\n删除下标 2 :[2,1,4] -> 偶数元素下标为:2 + 4 = 6 。奇数元素下标为:1 。不平衡。\n删除下标 3 :[2,1,6] -> 偶数元素下标为:2 + 6 = 8 。奇数元素下标为:1 。不平衡。\n只有一种让剩余数组成为平衡数组的方案。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [1,1,1]\n<b>输出:</b>3\n<b>解释:</b>你可以删除任意元素,剩余数组都是平衡数组。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<b>输入:</b>nums = [1,2,3]\n<b>输出:</b>0\n<b>解释:</b>不管删除哪个元素,剩下数组都不是平衡数组。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>4</sup></code></li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 30,
|
||||
"likes": 31,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -143,7 +143,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"6.1K\", \"totalSubmission\": \"11K\", \"totalAcceptedRaw\": 6088, \"totalSubmissionRaw\": 11027, \"acRate\": \"55.2%\"}",
|
||||
"stats": "{\"totalAccepted\": \"6.2K\", \"totalSubmission\": \"11.2K\", \"totalAcceptedRaw\": 6172, \"totalSubmissionRaw\": 11168, \"acRate\": \"55.3%\"}",
|
||||
"hints": [
|
||||
"The parity of the indices after the removed element changes.",
|
||||
"Calculate prefix sums for even and odd indices separately to calculate for each index in O(1)."
|
||||
|
Reference in New Issue
Block a user