1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-25 23:08:57 +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>给定一个二进制数组 <code>nums</code> 和一个整数 <code>k</code> 。</p>\n\n<p><strong>k位翻转</strong> 就是从 <code>nums</code> 中选择一个长度为 <code>k</code> 的 <strong>子数组</strong> ,同时把子数组中的每一个 <code>0</code> 都改成 <code>1</code> ,把子数组中的每一个 <code>1</code> 都改成 <code>0</code> 。</p>\n\n<p>返回数组中不存在 <code>0</code> 所需的最小 <strong>k位翻转</strong> 次数。如果不可能,则返回&nbsp;<code>-1</code>&nbsp;。</p>\n\n<p><strong>子数组</strong> 是数组的 <strong>连续</strong> 部分。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [0,1,0], K = 1\n<strong>输出:</strong>2\n<strong>解释:</strong>先翻转 A[0],然后翻转 A[2]。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,1,0], K = 2\n<strong>输出:</strong>-1\n<strong>解释:</strong>无论我们怎样翻转大小为 2 的子数组,我们都不能使数组变为 [1,1,1]。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [0,0,0,1,0,1,1,0], K = 3\n<strong>输出:</strong>3\n<strong>解释:</strong>\n翻转 A[0],A[1],A[2]:&nbsp;A变成 [1,1,1,1,0,1,1,0]\n翻转 A[4],A[5],A[6]:&nbsp;A变成 [1,1,1,1,1,0,0,0]\n翻转 A[5],A[6],A[7]:&nbsp;A变成 [1,1,1,1,1,1,1,1]\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;= k &lt;= nums.length</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 231,
"likes": 233,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Bulb Switcher\", \"titleSlug\": \"bulb-switcher\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u706f\\u6ce1\\u5f00\\u5173\"}]",
@@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"22.7K\", \"totalSubmission\": \"42.5K\", \"totalAcceptedRaw\": 22687, \"totalSubmissionRaw\": 42522, \"acRate\": \"53.4%\"}",
"stats": "{\"totalAccepted\": \"22.9K\", \"totalSubmission\": \"42.8K\", \"totalAcceptedRaw\": 22854, \"totalSubmissionRaw\": 42832, \"acRate\": \"53.4%\"}",
"hints": [],
"solution": {
"id": "143",