1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-03 14:32:54 +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>给你一个正整数数组&nbsp;<code>nums</code>,请你移除 <strong>最短</strong>&nbsp;子数组(可以为 <strong>空</strong>),使得剩余元素的 <strong>和</strong>&nbsp;能被 <code>p</code>&nbsp;整除。 <strong>不允许</strong>&nbsp;将整个数组都移除。</p>\n\n<p>请你返回你需要移除的最短子数组的长度,如果无法满足题目要求,返回 <code>-1</code>&nbsp;。</p>\n\n<p><strong>子数组</strong>&nbsp;定义为原数组中连续的一组元素。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>nums = [3,1,4,2], p = 6\n<strong>输出:</strong>1\n<strong>解释:</strong>nums 中元素和为 10不能被 p 整除。我们可以移除子数组 [4] ,剩余元素的和为 6 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>nums = [6,3,5,2], p = 9\n<strong>输出:</strong>2\n<strong>解释:</strong>我们无法移除任何一个元素使得和被 9 整除,最优方案是移除子数组 [5,2] ,剩余元素为 [6,3],和为 9 。\n</pre>\n\n<p><strong>示例&nbsp;3</strong></p>\n\n<pre><strong>输入:</strong>nums = [1,2,3], p = 3\n<strong>输出:</strong>0\n<strong>解释:</strong>和恰好为 6 ,已经能被 3 整除了。所以我们不需要移除任何元素。\n</pre>\n\n<p><strong>示例&nbsp; 4</strong></p>\n\n<pre><strong>输入:</strong>nums = [1,2,3], p = 7\n<strong>输出:</strong>-1\n<strong>解释:</strong>没有任何方案使得移除子数组后剩余元素的和被 7 整除。\n</pre>\n\n<p><strong>示例 5</strong></p>\n\n<pre><strong>输入:</strong>nums = [1000000000,1000000000,1000000000], p = 3\n<strong>输出:</strong>0\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= p &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 55,
"likes": 56,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"4.5K\", \"totalSubmission\": \"16.3K\", \"totalAcceptedRaw\": 4465, \"totalSubmissionRaw\": 16251, \"acRate\": \"27.5%\"}",
"stats": "{\"totalAccepted\": \"4.6K\", \"totalSubmission\": \"16.7K\", \"totalAcceptedRaw\": 4599, \"totalSubmissionRaw\": 16711, \"acRate\": \"27.5%\"}",
"hints": [
"Use prefix sums to calculate the subarray sums.",
"Suppose you know the remainder for the sum of the entire array. How does removing a subarray affect that remainder? What remainder does the subarray need to have in order to make the rest of the array sum up to be divisible by k?",