1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 05:26:46 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个下标从 <strong>0</strong>&nbsp;开始且长度为 <code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;。<strong>分割</strong>&nbsp;数组 <code>nums</code>&nbsp;的方案数定义为符合以下两个条件的 <code>pivot</code>&nbsp;数目:</p>\n\n<ul>\n\t<li><code>1 &lt;= pivot &lt; n</code></li>\n\t<li><code>nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1] + ... + nums[n - 1]</code></li>\n</ul>\n\n<p>同时给你一个整数&nbsp;<code>k</code>&nbsp;。你可以将&nbsp;<code>nums</code>&nbsp;中&nbsp;<strong>一个</strong>&nbsp;元素变为&nbsp;<code>k</code>&nbsp;或&nbsp;<strong>不改变</strong>&nbsp;数组。</p>\n\n<p>请你返回在 <strong>至多</strong>&nbsp;改变一个元素的前提下,<strong>最多</strong>&nbsp;有多少种方法 <strong>分割</strong>&nbsp;<code>nums</code>&nbsp;使得上述两个条件都满足。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><b>输入:</b>nums = [2,-1,2], k = 3\n<b>输出:</b>1\n<b>解释:</b>一个最优的方案是将 nums[0] 改为 k&nbsp;。数组变为 [<em><strong>3</strong></em>,-1,2] 。\n有一种方法分割数组\n- pivot = 2 ,我们有分割 [3,-1 | 2]3 + -1 == 2 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><b>输入:</b>nums = [0,0,0], k = 1\n<b>输出:</b>2\n<b>解释:</b>一个最优的方案是不改动数组。\n有两种方法分割数组\n- pivot = 1 ,我们有分割 [0 | 0,0]0 == 0 + 0 。\n- pivot = 2 ,我们有分割 [0,0 | 0]: 0 + 0 == 0 。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre><b>输入:</b>nums = [22,4,-25,-20,-15,15,-16,7,19,-10,0,-13,-14], k = -33\n<b>输出:</b>4\n<b>解释:</b>一个最优的方案是将 nums[2] 改为 k 。数组变为 [22,4,<em><strong>-33</strong></em>,-20,-15,15,-16,7,19,-10,0,-13,-14] 。\n有四种方法分割数组。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>n == nums.length</code></li>\n\t<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>-10<sup>5</sup> &lt;= k, nums[i] &lt;= 10<sup>5</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 23,
"likes": 26,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -161,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.6K\", \"totalSubmission\": \"5.8K\", \"totalAcceptedRaw\": 1602, \"totalSubmissionRaw\": 5801, \"acRate\": \"27.6%\"}",
"stats": "{\"totalAccepted\": \"1.7K\", \"totalSubmission\": \"6K\", \"totalAcceptedRaw\": 1662, \"totalSubmissionRaw\": 5971, \"acRate\": \"27.8%\"}",
"hints": [
"A pivot point splits the array into equal prefix and suffix. If no change is made to the array, the goal is to find the number of pivot p such that prefix[p-1] == suffix[p].",
"Consider how prefix and suffix will change when we change a number nums[i] to k.",